WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30449 closed defect (bug) (worksforme)

shortcode_parse_atts returns incorrect info

Reported by: nampara17 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0.1
Component: Shortcodes Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

The function shortcode_parse_atts returns an array but parses any params incorrectly

If you pass it:

title=”Tab 1 Title”

It returns:

(
    [title] => ”Tab
    [0] => 1
    [1] => Title”
)

and not:

(
    [title] => ”Tab 1 Title"
)

Never did this before and seems to be breaking wherever there are params with spaces (delimits on the spaces)

Change History (16)

#1 @gorman2001
5 years ago

It seems that curvy ("fancy") quotes interfere with the parsing process.

add_shortcode('test30449', function($atts) {
  var_dump($atts);
});

// Fails
do_shortcode('[test30449 title=”Tab 1 Title”]');
// OK
do_shortcode('[test30449 title="Tab 1 Title"]');

die();
Last edited 5 years ago by gorman2001 (previous) (diff)

#2 follow-up: @nampara17
5 years ago

yes seems that way, but the new editor seems to insist on adding these fancy quotes - even if you add the standard quotes - it converts them. Thus shortcodes that use this function will fail with the latest release.

I've tried many ways to put in quotes without it converting to fancy quotes. Could try the ascii codes or html chars - but that's not any solution - even if it does work.

Surely others have seen this issue?

#3 @nacin
5 years ago

Can you provide all of the surrounding content (such as a paragraph)? There is a separate method to curl quotes, and it runs before shortcodes are parsed. It doesn't have to do with the editor, but rather a separate filter that is run (much like shortcodes).

#4 in reply to: ↑ 2 ; follow-up: @miqrogroove
5 years ago

Replying to nampara17:

Surely others have seen this issue?

Please provide an example shortcode or entire post text if needed to replicate the problem. We can likely explain the problem then.

#5 in reply to: ↑ 4 @nampara17
5 years ago

Replying to miqrogroove:

Replying to nampara17:

Surely others have seen this issue?

Please provide an example shortcode or entire post text if needed to replicate the problem. We can likely explain the problem then.

<h2>THE CORE PROMISE</h2>
[five_sixth_last]
[tabs]
[tab title="Listen to Me"]An 'in' to hearing what ...
tab

Results in the result shown at the bottom of http://learn2live.mucllients.co.uk

The "listen to me" is not returned as one string as the speechmarks are not interpreted or ?

#6 @miqrogroove
5 years ago

Have you verified that the [tab] shortcode is actually registered? The symptoms described so far would result from trying to use a shortcode that doesn't exist. There is more info about that problem here:

http://codex.wordpress.org/Shortcode_API#Unregistered_Names

Last edited 5 years ago by miqrogroove (previous) (diff)

#7 @miqrogroove
5 years ago

And is the problem related to this plugin? https://wordpress.org/plugins/tabs-shortcode/

#8 follow-up: @miqrogroove
5 years ago

Also, your URL appears to be broken. I don't think we have enough information yet to identify a bug.

#9 in reply to: ↑ 8 @gorman2001
5 years ago

Replying to miqrogroove:

Also, your URL appears to be broken. I don't think we have enough information yet to identify a bug.

The bug occurs without a specific plugin (see my example code above). It occurs because of the curly quotes not being parsed by shortcode_parse_atts.

If it's not a bug, then a small mention in the docs would be useful.

#10 follow-up: @miqrogroove
5 years ago

hi gorman2001, your example does not conform to the shortcode syntax.

#11 in reply to: ↑ 10 ; follow-up: @gorman2001
5 years ago

Replying to miqrogroove:

hi gorman2001, your example does not conform to the shortcode syntax.

In which way?

#12 in reply to: ↑ 11 @miqrogroove
5 years ago

Replying to gorman2001:

In which way?

You have not identified anything contrary to the documented design of the API. Unless nampara17 can tell us how to replicate his bug, we have nothing to fix.

#13 @miqrogroove
5 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Good news/bad news. I figured out nampara17 is using WP Shortcode by MyThemeShop. The bug is here:

http://plugins.svn.wordpress.org/wp-shortcode/tags/1.2/wp-shortcode.php

On line 341 the plugin uses customized regex to parse an unregistered shortcode. The plugin also does not use the no_texturize_shortcodes filter, so the core code has no way of knowing that the [tag] phrase is a shortcode.

Please contact the plugin developer about these problems and reference this page: http://codex.wordpress.org/Shortcode_API#Unregistered_Names

Last edited 5 years ago by miqrogroove (previous) (diff)

#14 @SergeyBiryukov
5 years ago

  • Description modified (diff)
  • Milestone Awaiting Review deleted

#15 @nampara17
5 years ago

whoops sorry link was my bad:

http://learn2live.muclients.co.uk

You are right it uses a theme from mythemeshop with a tabs plugin from the same company. Issue only shows from 4.0.1 onwards. I have sent this issue back to the developers rather than hack the plugin myself. Is there an easy intermediate fix?

Would registering the shortcode help the issue in the short term?

Cheers

#16 @miqrogroove
5 years ago

I think the [tags] shortcode needs to be added to the no_texturize_shortcodes filter so that the nested code is unaffected.

Note: See TracTickets for help on using tickets.