Skip to content

Commit

Permalink
test: improve hack options injection
Browse files Browse the repository at this point in the history
examples including a `hackOptions` snippet would have the snippet replaced instead of the actual `hackOptions` code; strip the comment out to avoid this issue
  • Loading branch information
seleb committed Dec 3, 2020
1 parent d2a0b7a commit 11b119f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/test/bitsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ export async function start({
return `<script>${hackDist[hack.replace(/\s/g, '-')].replace(/\$([0-9]+)/g, '$$$$$1')}</script>`;
}
const [hackStr, options] = hack;
return `<script>${hackDist[hackStr.replace(/\s/g, '-')].replace(/(var hackOptions.*=)[^]*?;$/m, `$1 ${JSON.stringify(options, undefined, '\t')};`).replace(/\$([0-9]+)/g, '$$$$$1')}</script>`;
return `<script>${
hackDist[hackStr.replace(/\s/g, '-')]
// remove comments (they can interfer with hackOptions regex)
.replace(/\/\*\*[^]*?\*\//m)
// replace hackOptions
.replace(/(var hackOptions.*= ){[^]*?};$/m, `$1 ${JSON.stringify(options, undefined, '\t')};`)
// make sure not to screw up the regex in the process
.replace(/\$([0-9]+)/g, '$$$$$1')
}</script>`;
}).join('\n')
}$2`);
}
Expand Down

0 comments on commit 11b119f

Please sign in to comment.