Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regex to not mix self closing tags #1328

merged 1 commit into from Oct 27, 2015


Copy link

@SergioCrisostomo SergioCrisostomo commented Oct 24, 2015

fixes #1022

@@ -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+');
Copy link

@arian arian Oct 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before the :.

Copy link

arian commented Oct 25, 2015

Could you elaborate the change?

Copy link
Member Author

SergioCrisostomo commented Oct 25, 2015

@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 + "([^>]+)?>";


"<\/?" + 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.

Copy link

anutron commented Oct 27, 2015


SergioCrisostomo added a commit that referenced this pull request Oct 27, 2015
fix regex to not mix self closing tags
@SergioCrisostomo SergioCrisostomo merged commit 899de1f into mootools:master Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

String.stripTags mixed some tags
3 participants