[wp-trac] [WordPress Trac] #35545: Unexpected behavior of wp.shortcode.regexp

WordPress Trac noreply at wordpress.org
Wed Jan 20 14:09:52 UTC 2016


#35545: Unexpected behavior of wp.shortcode.regexp
--------------------------+-----------------------------
 Reporter:  TobiasHoessl  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Shortcodes    |    Version:  4.4.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Using the _.memoize-Function for wp.shortcode.regexp (defined in /wp-
 includes/js/shortcode.js) leads to somewhat surprising behavior of the
 returned Regexp-Object:

 {{{
 > wp.shortcode.regexp("foo").exec("[foo]bar[/foo]")
 -> ["[foo]bar[/foo]", "", "foo", "", undefined, "bar", "[/foo]", ""]

 > wp.shortcode.regexp("foo").exec("[foo]bar[/foo]")
 -> null

 > wp.shortcode.regexp("foo").exec("[foo]bar[/foo]")
 -> ["[foo]bar[/foo]", "", "foo", "", undefined, "bar", "[/foo]", ""]

 > wp.shortcode.regexp("foo").exec("[foo]bar[/foo]")
 -> null
 ...
 }}}

 I would expect the call to return the same result every time and not
 "null" every second time. This happens because the Regexp-Object is
 recycled and Regexp just seems to behave this way. However when using
 wp.shortcode.regexp-Function without knowing the internal behavior of the
 Regexp-Object, this comes rather surprising. Maybe not caching this object
 might be a better choice here.

 For example, the Shortcode-UI-Plugin (https://wordpress.org/plugins
 /shortcodes-ui/) seems to have a problem because of this.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35545>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list