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

Projects
None yet
3 participants
@SergioCrisostomo
Member

SergioCrisostomo commented Oct 24, 2015

fixes #1022

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

This comment has been minimized.

@arian

arian Oct 25, 2015

Member

Space before the :.

@arian

arian Oct 25, 2015

Member

Space before the :.

@arian

This comment has been minimized.

Show comment
Hide comment
@arian

arian Oct 25, 2015

Member

Could you elaborate the change?

Member

arian commented Oct 25, 2015

Could you elaborate the change?

@SergioCrisostomo

This comment has been minimized.

Show comment
Hide comment
@SergioCrisostomo

SergioCrisostomo Oct 25, 2015

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@anutron

anutron Oct 27, 2015

Member

👍

Member

anutron commented Oct 27, 2015

👍

SergioCrisostomo added a commit that referenced this pull request Oct 27, 2015

Merge pull request #1328 from SergioCrisostomo/fix-1022
fix regex to not mix self closing tags

@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