This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #26459 from KevinGrandon/bug_1101158_use_tagged_te…
…mplate Bug 1101158 - Use shared tagged template library for escaping card content
- Loading branch information
Showing
6 changed files
with
88 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* global Tagged */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| require('/shared/js/tagged.js'); | ||
|
|
||
| suite('tagged template helper', function() { | ||
|
|
||
| test('#escapeHTML', function() { | ||
| var myVal = '<b>hello</b>'; | ||
| // fix a jshint issue with tagged template strings | ||
| // https://github.com/jshint/jshint/issues/2000 | ||
| /* jshint -W033 */ | ||
| var generated = Tagged.escapeHTML `${myVal} world`; | ||
| /* jshint +W033 */ | ||
| assert.equal(generated, '<b>hello</b> world'); | ||
| }); | ||
| }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * tagged.js is a simple library to help you manage tagged template strings. | ||
| */ | ||
| var Tagged = { | ||
|
|
||
| _entity: /[&<>"'/]/g, | ||
|
|
||
| _entities: { | ||
| '&': '&', | ||
| '<': '<', | ||
| '>': '>', | ||
| '"': '"', | ||
| '\'': ''', | ||
| '/': '/' | ||
| }, | ||
|
|
||
| getEntity: function(s) { | ||
| return Tagged._entities[s]; | ||
| }, | ||
|
|
||
| /** | ||
| * Escapes HTML for all values in a tagged template string. | ||
| */ | ||
| escapeHTML: function(strings, ...values) { | ||
| var result = ''; | ||
|
|
||
| for (var i = 0; i < strings.length; i++) { | ||
| result += strings[i]; | ||
| if (i < values.length) { | ||
| result += String(values[i]).replace(Tagged._entity, Tagged.getEntity); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| }; |