[wp-trac] [WordPress Trac] #34831: WP oEmbed: Validate the "Secret" When Used in `document.querySelectorAll()`
WordPress Trac
noreply at wordpress.org
Thu Dec 3 17:15:50 UTC 2015
#34831: WP oEmbed: Validate the "Secret" When Used in `document.querySelectorAll()`
------------------------------+-------------------------
Reporter: mdawaffe | Owner: pento
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 4.4
Component: Embeds | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch commit | Focuses: javascript
------------------------------+-------------------------
Comment (by swissspidy):
Replying to [comment:5 pento]:
> Is `/[^a-zA-Z0-9]/.test( data.secret )` or `data.secret.match(
/[^a-zA-Z0-9]/ )` better?
`test()` returns a bool, whereas `match()` returns all the matches. For
that reason, `test()` is much faster.
MDN [https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/match recommends]
using `search()` if you need to know if a string matches a regular
expression. `search()` returns the index of the first match or `-1`.
[http://jsperf.com/exec-vs-match-vs-test-vs-search/98 This comparison
between all those functions] shows that `search()` and `test()` are both
much, much faster than the other methods.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34831#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list