Skip to content

Commit

Permalink
Escape only < in front-end json (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaperStrike authored Jun 18, 2021
1 parent 81f716d commit 566238d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
3 changes: 1 addition & 2 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ hexo.extend.helper.register('next_vendors', function(name) {
});

hexo.extend.helper.register('next_data', function(name, ...data) {
const { escape_html } = this;
const json = data.length === 1 ? data[0] : Object.assign({}, ...data);
return `<script class="next-config" data-name="${name}" type="application/json">${
escape_html(JSON.stringify(json))
JSON.stringify(json).replace(/</g, '\\u003c')
}</script>`;
});

Expand Down
7 changes: 1 addition & 6 deletions source/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ if (!window.NexT) window.NexT = {};
const staticConfig = {};
let variableConfig = {};

const parse = text => {
const jsonString = new DOMParser()
.parseFromString(text, 'text/html').documentElement
.textContent;
return JSON.parse(jsonString || '{}');
};
const parse = text => JSON.parse(text || '{}');

const update = name => {
const targetEle = document.querySelector(`.${className}[data-name="${name}"]`);
Expand Down

0 comments on commit 566238d

Please sign in to comment.