Skip to content
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

Reduce risk of XSS #1051

Merged
merged 5 commits into from
Nov 20, 2016
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
8 changes: 3 additions & 5 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,9 @@ Token.stringify = function(o, language, parent) {

_.hooks.run('wrap', env);

var attributes = '';

for (var name in env.attributes) {
attributes += (attributes ? ' ' : '') + name + '="' + (env.attributes[name] || '') + '"';
}
var attributes = Object.keys(env.attributes).map(function(name) {
return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
}).join(' ');

return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';

Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions plugins/command-line/prism-command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ Prism.hooks.add('complete', function (env) {
pre.className += ' command-line';
}

var getAttribute = function(key, defaultValue) {
return (pre.getAttribute(key) || defaultValue).replace(/"/g, '&quot');
};

// Create the "rows" that will become the command-line prompts. -- cwells
var lines = new Array(1 + env.code.split('\n').length);
var promptText = pre.getAttribute('data-prompt') || '';
var promptText = getAttribute('data-prompt', '');
if (promptText !== '') {
lines = lines.join('<span data-prompt="' + promptText + '"></span>');
} else {
var user = pre.getAttribute('data-user') || 'user';
var host = pre.getAttribute('data-host') || 'localhost';
var user = getAttribute('data-user', 'user');
var host = getAttribute('data-host', 'localhost');
lines = lines.join('<span data-user="' + user + '" data-host="' + host + '"></span>');
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/command-line/prism-command-line.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Prism.plugins.toolbar.registerButton('show-language', function(env) {
var language = pre.getAttribute('data-language') || Languages[env.language] || (env.language.substring(0, 1).toUpperCase() + env.language.substring(1));

var element = document.createElement('span');
element.innerHTML = language;
element.textContent = language;

return element;
});
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/toolbar/prism-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
element = document.createElement('span');
}

element.innerHTML = text;
element.textContent = text;
}

return element;
Expand Down
Loading