Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($compile): correctly handle null/undefined href attrs.$set() #16520

Merged
merged 1 commit into from
Apr 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if ((nodeName === 'a' && (key === 'href' || key === 'xlinkHref')) ||
(nodeName === 'img' && key === 'src')) {
// sanitize a[href] and img[src] values
this[key] = value = $$sanitizeUri(value, key === 'src');
this[key] = value = (value == null) ? value : $$sanitizeUri(value, key === 'src');
Copy link
Member

Choose a reason for hiding this comment

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

Are those parens around value == null necessary? ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, but look how much cleaner it looks with the parens 😛

Copy link
Member

Choose a reason for hiding this comment

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

De gustibus etc. but I'm not insisting. ;)

} else if (nodeName === 'img' && key === 'srcset' && isDefined(value)) {
// sanitize img[srcset] values
var result = '';
Expand Down Expand Up @@ -1761,7 +1761,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}

if (writeAttr !== false) {
if (value === null || isUndefined(value)) {
if (value == null) {
this.$$element.removeAttr(attrName);
} else {
if (SIMPLE_ATTR_NAME.test(attrName)) {
Expand Down