Fix: OG messed up if $"
is in title
## Issue 5951: OG messed up if `$"` is in title The replacement string would contain `...$"...`. 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:
parent
2d66b8666d
commit
4156e83f57
1 changed files with 11 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue