fix regex to not mix self closing tags #1328

Merged
merged 1 commit into from Oct 27, 2015

Projects

None yet

3 participants

@SergioCrisostomo
Member

fixes #1022

@arian arian commented on an outdated diff Oct 25, 2015
Source/Types/String.Extras.js
@@ -95,8 +95,8 @@ var walk = function(string, replacements){
};
var getRegexForTag = function(tag, contents){
- tag = tag || '';
- var regstr = contents ? "<" + tag + "(?!\\w)[^>]*>([\\s\\S]*?)<\/" + tag + "(?!\\w)>" : "<\/?" + tag + "([^>]+)?>";
+ tag = tag || (contents ? '': '\\w+');
@arian
arian Oct 25, 2015 Member

Space before the :.

@arian
Member
arian commented Oct 25, 2015

Could you elaborate the change?

@SergioCrisostomo
Member

@arian sure, should have done that in the first place, sorry.

This change only applies to cases where contents has boolean value false, and so the change is from

"<\/?" + tag + "([^>]+)?>";

to

"<\/?" + tag + "\/?>|<" + tag + "[\\s|\/][^>]*>"

and in cases where tag has boolean value false, tag will be '\\w+'.

As it was str.stripTags("b") would also strip <br/> tags since the regex would be <\/?b([^>]+)?>.

So the first alternative in the new regex suggestion is for simpler tags (closing or self-closing), and the second alternative is for self-closing, opening, and tags with attributes. This way it will never match a letter after the tag that was passed to the method.

@anutron
Member
anutron commented Oct 27, 2015

👍

@SergioCrisostomo SergioCrisostomo merged commit 899de1f into mootools:master Oct 27, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment