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();
|
const jsBundleId = getJsBundleId();
|
||||||
|
|
||||||
function insertToHead(fullHtml, htmlToInsert) {
|
function insertToHead(fullHtml, htmlToInsert) {
|
||||||
return fullHtml.replace(
|
const beginStr = '<!-- VARIABLE_HEAD_BEGIN -->';
|
||||||
/<!-- VARIABLE_HEAD_BEGIN -->.*<!-- VARIABLE_HEAD_END -->/s,
|
const finalStr = '<!-- VARIABLE_HEAD_END -->';
|
||||||
`
|
|
||||||
${htmlToInsert || buildOgMetadata()}
|
const beginIndex = fullHtml.indexOf(beginStr);
|
||||||
<script src="/public/ui-${jsBundleId}.js" async></script>
|
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) {
|
function truncateDescription(description) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue