-
-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
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
Co-authored-by: Gardar Hauksson <[email protected]>
- Loading branch information
Showing
7 changed files
with
123 additions
and
1 deletion.
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
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,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Escape parameter HTML example</title> | ||
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/vue-i18n.esm.browser.js"></script> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
<p v-html="displayMsg"></p> | ||
</div> | ||
<script> | ||
const i18n = new VueI18n({ | ||
locale: 'en', | ||
escapeParameterHtml: true, | ||
messages: { | ||
en: { | ||
message: 'User input: <b>{value}</b>', | ||
} | ||
} | ||
}) | ||
new Vue({ | ||
el: '#app', | ||
i18n: i18n, | ||
computed: { | ||
displayMsg() { | ||
return this.$t('message', {value: '<img src="" onError="alert(42)">'}) | ||
} | ||
} | ||
}) | ||
</script> | ||
</body> | ||
</html> |
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,29 @@ | ||
const messages = { | ||
en: { | ||
listformat: '{0}', | ||
nameformat: '{key}', | ||
} | ||
} | ||
|
||
describe('escapeParameterHtml', () => { | ||
it('Replacement parameters are escaped when escapeParameterHtml: true.', () => { | ||
const i18n = new VueI18n({ | ||
locale: 'en', | ||
messages, | ||
escapeParameterHtml: true | ||
}) | ||
assert(i18n.t('nameformat', { key: '<&"\'>' }) === '<&"'>') | ||
assert(i18n.t('listformat', ['<&"\'>']) === '<&"'>') | ||
assert(i18n.tc('nameformat', 1, { key: '<&"\'>' }).toString() === '<&"'>') | ||
assert(i18n.tc('listformat', 1, ['<&"\'>']).toString() === '<&"'>') | ||
}) | ||
it('Replacement parameters are not escaped when escapeParameterHtml: undefined.', () => { | ||
const i18n = new VueI18n({ | ||
locale: 'en', | ||
messages, | ||
}) | ||
assert(i18n.t('nameformat', { key: '<&"\'>' }) === '<&"\'>') | ||
assert(i18n.t('listformat', ['<&"\'>']) === '<&"\'>') | ||
|
||
}) | ||
}) |
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