Skip to content

Commit

Permalink
html encode the reflected query parameters (ampproject#6680)
Browse files Browse the repository at this point in the history
* html encode the reflected query parameters

* fix lint issues
  • Loading branch information
erwinmombay committed Oct 6, 2023
1 parent f085239 commit 8358cb4
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const {STYLE} = require('../cache.js');

const htmlEncode = (str) => {
return String(str).replace(/[^\w. ]/gi, (c) => {
return `&#${c.charCodeAt(0)};`;
});
};

const handler = async (ev) => {
const queryString = JSON.stringify(ev.queryStringParameters, null, 2);

Expand All @@ -19,7 +25,7 @@ const handler = async (ev) => {
<main>
<h1>Hello World!</h1>
<p>Query parameters:</p>
<pre>${queryString}</pre>
<pre>${htmlEncode(queryString)}</pre>
<small>This document has been generated at: <date>${new Date()}</date></small>
</main>
</body>
Expand Down

0 comments on commit 8358cb4

Please sign in to comment.