forked from kazupon/vue-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add escapeParameterHtml parameter. kazupon#1002
- Loading branch information
Gardar Hauksson
committed
Oct 6, 2020
1 parent
5ba214d
commit 614fc8e
Showing
7 changed files
with
127 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/vue-i18n@8.22.0/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,27 @@ | ||
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', ['<&"\'>']) === '<&"'>') | ||
}) | ||
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