Fix: OG messed up if $" is in title

## Issue
5951: OG messed up if `$"` is in title

The replacement string would contain `...$&quot...`. The character `$&` has special meaning in `replace`, so the output was messed up.

## Approach
Use a direct slice approach. A bit less elegant.
This commit is contained in:
infinite-persistence 2021-08-02 22:10:49 +08:00 committed by jessopb
parent 2d66b8666d
commit 4156e83f57

View file

@ -23,13 +23,17 @@ const { getJsBundleId } = require('../bundle-id.js');
const jsBundleId = getJsBundleId();
function insertToHead(fullHtml, htmlToInsert) {
return fullHtml.replace(
/<!-- VARIABLE_HEAD_BEGIN -->.*<!-- VARIABLE_HEAD_END -->/s,
`
${htmlToInsert || buildOgMetadata()}
<script src="/public/ui-${jsBundleId}.js" async></script>
`
);
const beginStr = '<!-- VARIABLE_HEAD_BEGIN -->';
const finalStr = '<!-- VARIABLE_HEAD_END -->';
const beginIndex = fullHtml.indexOf(beginStr);
const finalIndex = fullHtml.indexOf(finalStr);
if (beginIndex > -1 && finalIndex > -1 && finalIndex > beginIndex) {
return `${fullHtml.slice(0, beginIndex)}${
htmlToInsert || buildOgMetadata()
}<script src="/public/ui-${jsBundleId}.js" async></script>${fullHtml.slice(finalIndex + finalStr.length)}`;
}
}
function truncateDescription(description) {