Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a limit, in more places, when splitting strings #17619

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/chromium/extension-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ limitations under the License.
}
var scheme = url.slice(0, schemeIndex).toLowerCase();
if (schemes.includes(scheme)) {
url = url.split("#")[0];
url = url.split("#", 1)[0];
if (url.charAt(schemeIndex) === ":") {
url = encodeURIComponent(url);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3955,7 +3955,7 @@ class PartialEvaluator {

isSerifFont(baseFontName) {
// Simulating descriptor flags attribute
const fontNameWoStyle = baseFontName.split("-")[0];
const fontNameWoStyle = baseFontName.split("-", 1)[0];
return (
fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle)
);
Expand Down Expand Up @@ -4185,7 +4185,7 @@ class PartialEvaluator {
const metrics = this.getBaseFontMetrics(baseFontName);

// Simulating descriptor flags attribute
const fontNameWoStyle = baseFontName.split("-")[0];
const fontNameWoStyle = baseFontName.split("-", 1)[0];
const flags =
(this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
(metrics.monospace ? FontFlags.FixedPitch : 0) |
Expand Down
4 changes: 2 additions & 2 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ class Font {
// Fallback to checking the font name, in order to improve text-selection,
// since the /Flags-entry is often wrong (fixes issue13845.pdf).
if (!isSerifFont && !properties.isSimulatedFlags) {
const baseName = name.replaceAll(/[,_]/g, "-").split("-")[0],
const baseName = name.replaceAll(/[,_]/g, "-").split("-", 1)[0],
serifFonts = getSerifFonts();
for (const namePart of baseName.split("+")) {
if (serifFonts[namePart]) {
Expand Down Expand Up @@ -1286,7 +1286,7 @@ class Font {
}

amendFallbackToUnicode(properties);
this.loadedName = fontName.split("-")[0];
this.loadedName = fontName.split("-", 1)[0];
}

checkAndRepair(name, font, properties) {
Expand Down
2 changes: 1 addition & 1 deletion test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ class Driver {
if (!("message" in e)) {
return JSON.stringify(e);
}
return e.message + ("stack" in e ? " at " + e.stack.split("\n")[0] : "");
return e.message + ("stack" in e ? " at " + e.stack.split("\n", 1)[0] : "");
}

_getLastPageNumber(task) {
Expand Down
2 changes: 1 addition & 1 deletion web/generic_scripting.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getPdfFilenameFromUrl } from "pdfjs-lib";

async function docProperties(pdfDocument) {
const url = "",
baseUrl = url.split("#")[0];
baseUrl = url.split("#", 1)[0];
// eslint-disable-next-line prefer-const
let { info, metadata, contentDispositionFilename, contentLength } =
await pdfDocument.getMetadata();
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class PDFHistory {

let newUrl;
if (this._updateUrl && destination?.hash) {
const baseUrl = document.location.href.split("#")[0];
const baseUrl = document.location.href.split("#", 1)[0];
// Prevent errors in Firefox.
if (!baseUrl.startsWith("file://")) {
newUrl = `${baseUrl}#${destination.hash}`;
Expand Down