Skip to content

555 - Fix HTML value not escaped in DataField #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion shells/dev/target/NativeTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export default {
},
largeArray: [],
i: new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])]),
j: new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])], [8, new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])])]])
j: new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])], [8, new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])])]]),
html: '<b>Bold</b> <i>Italic</i>'
}
},
computed: {
Expand Down
5 changes: 3 additions & 2 deletions src/devtools/components/DataField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ import {
NAN,
isPlainObject,
sortByKey,
openInEditor
openInEditor,
escape
} from 'src/util'

import DataFieldEdit from '../mixins/data-field-edit'
Expand Down Expand Up @@ -285,7 +286,7 @@ export default {
if (typeMatch) {
return typeMatch[1]
} else {
return `<span>"</span>${value}<span>"</span>`
return `<span>"</span>${escape(value)}<span>"</span>`
}
} else {
return value
Expand Down
15 changes: 15 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,18 @@ export function openInEditor (file) {
eval(src)
}
}

const ESC = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to add = and ' too?

'&': '&amp;'
}

export function escape (s) {
return s.replace(/[<>"&]/g, escapeChar)
}

function escapeChar (a) {
return ESC[a] || a
}