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
merged 1 commit into from Oct 27, 2015

Conversation

@SergioCrisostomo
Copy link
Member

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

This comment has been minimized.

Copy link
@arian

arian Oct 25, 2015

Member

Space before the :.

@arian
Copy link
Member

arian commented Oct 25, 2015

Could you elaborate the change?

@SergioCrisostomo SergioCrisostomo force-pushed the SergioCrisostomo:fix-1022 branch from cdd7f90 to b171c49 Oct 25, 2015
@SergioCrisostomo
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 + "([^>]+)?>";

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 SergioCrisostomo force-pushed the SergioCrisostomo:fix-1022 branch from b171c49 to bd14bbb 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
1 check passed
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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.