Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
fix($translateSanitizationProvider): fix sanitization of boolean values
Browse files Browse the repository at this point in the history
When using `$translateSanitizationProvider` with `escapeParameters` or `sanitizeParameters` strategy boolean values transformed to strings, e.g. `false` becomes `"false"`.
With this fix boolean values are not transformed.

Closes #1747
  • Loading branch information
afitiskin authored and knalli committed Jun 22, 2017
1 parent b3b04bd commit 70f4843
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/service/sanitization.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ function $translateSanitizationProvider () {
return result;
} else if (angular.isNumber(value)) {
return value;
} else if (value === true || value === false) {
return value;
} else if (!angular.isUndefined(value) && value !== null) {
return iteratee(value);
} else {
Expand Down
15 changes: 10 additions & 5 deletions test/unit/service/sanitization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('pascalprecht.translate', function () {
var parameters = {
array : [
{value : 'This is <b>only an example with a <span onclick="alert(\'XSS\')">xss attack</span>!</b>'}
]
],
boolean: false
},
text = 'This is <b>only an example with a <span onclick="alert(\'XSS\')">xss attack</span>!</b>',
expectedParameters,
Expand Down Expand Up @@ -96,7 +97,8 @@ describe('pascalprecht.translate', function () {
expectedParameters = {
array : [
{value : 'This is <b>only an example with a <span>xss attack</span>!</b>'}
]
],
boolean: false
};
expect($translateSanitization.sanitize(parameters, 'params')).toEqual(expectedParameters);
});
Expand All @@ -116,7 +118,8 @@ describe('pascalprecht.translate', function () {
expectedParameters = {
array : [
{value : 'This is &lt;b&gt;only an example with a &lt;span onclick="alert(\'XSS\')"&gt;xss attack&lt;/span&gt;!&lt;/b&gt;'}
]
],
boolean: false
};
expect($translateSanitization.sanitize(parameters, 'params')).toEqual(expectedParameters);
});
Expand Down Expand Up @@ -162,7 +165,8 @@ describe('pascalprecht.translate', function () {
expectedParameters = {
array : [
{value : 'This is &lt;b&gt;only an example with a &lt;span onclick="alert(\'XSS\')"&gt;xss attack&lt;/span&gt;!&lt;/b&gt;'}
]
],
boolean: false
};
expect($translateSanitization.sanitize(parameters, 'params')).toEqual(expectedParameters);
});
Expand All @@ -182,7 +186,8 @@ describe('pascalprecht.translate', function () {
expectedParameters = {
array : [
{value : 'This is &lt;b&gt;only an example with a &lt;span onclick="alert(\'XSS\')"&gt;xss attack&lt;/span&gt;!&lt;/b&gt;'}
]
],
boolean: false
};
expect($translateSanitization.sanitize(parameters, 'params')).toEqual(expectedParameters);
});
Expand Down

0 comments on commit 70f4843

Please sign in to comment.