Merge pull request #21497 from Snuffleupagus/substring-tweaks

Tweak some `String.prototype.substring()` usage
This commit is contained in:
Jonas Jenwald 2026-06-24 20:32:34 +02:00 committed by GitHub
commit 10844326c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 8 deletions

View File

@ -3124,7 +3124,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
}
if (startChunk < line.length) {
chunks.push(line.substring(startChunk, line.length));
chunks.push(line.substring(startChunk));
}
return chunks;

View File

@ -386,7 +386,7 @@ function escapePDFName(str) {
}
if (start < str.length) {
buffer.push(str.substring(start, str.length));
buffer.push(str.substring(start));
}
return buffer.join("");
@ -545,7 +545,7 @@ function encodeToXmlString(str) {
return str;
}
if (start < str.length) {
buffer.push(str.substring(start, str.length));
buffer.push(str.substring(start));
}
return buffer.join("");
}

View File

@ -17,6 +17,7 @@
// https://github.com/mozilla/shumway/blob/16451d8836fa85f4b16eeda8b4bda2fa9e2b22b0/src/avm2/natives/xml.ts
import { encodeToXmlString } from "./core_utils.js";
import { shadow } from "../shared/util.js";
const XMLParserErrorCode = {
NoError: 0,
@ -47,12 +48,17 @@ function isWhitespaceString(s) {
}
class XMLParserBase {
static get _entityRegex() {
return shadow(this, "_entityRegex", /&(?:#x([^;]+)|#([^;]+)|([^;]+));/g);
}
_resolveEntities(s) {
return s.replaceAll(/&([^;]+);/g, (all, entity) => {
if (entity.substring(0, 2) === "#x") {
return String.fromCodePoint(parseInt(entity.substring(2), 16));
} else if (entity.at(0) === "#") {
return String.fromCodePoint(parseInt(entity.substring(1), 10));
return s.replaceAll(XMLParserBase._entityRegex, (_, hex, dec, entity) => {
if (hex) {
return String.fromCodePoint(parseInt(hex, 16));
}
if (dec) {
return String.fromCodePoint(parseInt(dec, 10));
}
switch (entity) {
case "lt":