-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($compile): sanitize special chars in directive name #16314
fix($compile): sanitize special chars in directive name #16314
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
f45484a
to
3ba25d6
Compare
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
c42eccd
to
7c2e14b
Compare
There some test failures with jquery: https://travis-ci.org/angular/angular.js/jobs/295785053 |
@Narretz yes, I'm trying to understand why I have them passing locally at 4 browsers but not in CI... |
Are you sure you are running |
I was running |
I wonder if it is trying to convert |
7c2e14b
to
5e859dd
Compare
Checked how |
5e859dd
to
18226ee
Compare
Doh... |
this fixes bug introduced in 1.6.x when directive name with preceeding special char in HTML markup does not match the registered name
18226ee
to
6a20b35
Compare
Aren't we creating an inconsistent and undocumented behavior? Because afaik there's nothing about the handling of special characters at the start of a directive name in the docs. The docs:
It doesn't say that :, -, or _ are stripped from the front. |
src/ng/compile.js
Outdated
@@ -3637,7 +3637,7 @@ function SimpleChange(previous, current) { | |||
SimpleChange.prototype.isFirstChange = function() { return this.previousValue === _UNINITIALIZED_VALUE; }; | |||
|
|||
|
|||
var PREFIX_REGEXP = /^((?:x|data)[:\-_])/i; | |||
var PREFIX_REGEXP = /^((?:x|data)*[:\-_])/i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The *
is wrong. Use ?
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkalpak looking through usage of new function, its implementation is actually correct for CSS, so changing it back might break the desired behaviour there... should I add yet another camelcasing method? |
src/ng/compile.js
Outdated
.replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) { | ||
return offset ? letter.toUpperCase() : letter; | ||
}) | ||
.replace(MOZ_HACK_REGEXP, 'Moz$1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, this was only necessary for CSS, so we don't need it here any more.
src/ng/compile.js
Outdated
* Also there is special case for Moz prefix starting with upper case letter. | ||
* @param name Name to normalize | ||
*/ | ||
function camelCase(name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function is only used in directiveNormalize()
it makes sense to inline the code there.
More or less. I.e. you just need to update |
b6fdcde
to
e126f72
Compare
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
e126f72
to
e6d2439
Compare
test/ng/compileSpec.js
Outdated
@@ -294,6 +294,26 @@ describe('$compile', function() { | |||
inject(function($compile) {}); | |||
}); | |||
|
|||
it('should omit special chars before processing directive name', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this applies only to directives with restrict: 'A', then the test description should reflect that. Maybe even link to this issue in a comment.
273021a
to
ca546c8
Compare
ca546c8
to
a3a91aa
Compare
@Narretz @gkalpak @petebacondarwin any other ideas for improvement? |
test/ng/compileSpec.js
Outdated
}); | ||
}); | ||
inject(function($compile, $rootScope, log) { | ||
element = $compile('<div _t></div>')($rootScope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The element =
parts are redundant.
test/ng/compileSpec.js
Outdated
@@ -294,6 +294,27 @@ describe('$compile', function() { | |||
inject(function($compile) {}); | |||
}); | |||
|
|||
it('should omit special chars before processing attribute directive name', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change "omit" to "ignore", because I think it bettr describes the behavior.
4ecd741
to
adc359f
Compare
22c40fb
to
fc0811f
Compare
fc0811f
to
b8807dc
Compare
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Fix for
What is the current behavior? (You can also link to an open issue here)
In HTML markup only directive name's
x-
anddata-
prefixes are being sanitized. (#16278)What is the new behavior (if this is a feature change)?
Also special chars are being sanitized, e.g.
<div _t></div>
will matcht
directive once againDoes this PR introduce a breaking change?
Should not
Please check if the PR fulfills these requirements
Other information:
@petebacondarwin suggested to update the regex, and I hope that I did it in a way he was thinking about it.