Skip to content

fix regex to not mix self closing tags#1328

Merged
SergioCrisostomo merged 1 commit intomootools:masterfrom
SergioCrisostomo:fix-1022
Oct 27, 2015
Merged

fix regex to not mix self closing tags#1328
SergioCrisostomo merged 1 commit intomootools:masterfrom
SergioCrisostomo:fix-1022

Conversation

@SergioCrisostomo
Copy link
Member

fixes #1022

Copy link
Member

Choose a reason for hiding this comment

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

Space before the :.

@arian
Copy link
Member

arian commented Oct 25, 2015

Could you elaborate the change?

@SergioCrisostomo
Copy link
Member Author

@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
Copy link
Member

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String.stripTags mixed some tags

3 participants