diff --git a/apps/server/src/provider/documentTextWorker.ts b/apps/server/src/provider/documentTextWorker.ts index 4b5002250eb2..f3d7e0b3d360 100644 --- a/apps/server/src/provider/documentTextWorker.ts +++ b/apps/server/src/provider/documentTextWorker.ts @@ -296,18 +296,40 @@ function hasImportantDisplayNone(style: string): boolean { return false; let badString = false; const declarations = style.replaceAll( - /\/\*[\s\S]*?(?:\*\/|$)|"[^"]*(?:"|$)|'[^']*(?:'|$)/g, + /(? { if (token.startsWith("/")) return " "; + // Unquoted URLs keep comment and bracket characters as content. + if (/^url/i.test(token)) { + if (!/^url\([\t\n\f\r ]*[^\s"'()]*[\t\n\f\r ]*\)$/i.test(token)) badString = true; + return "url()"; + } // CSS ends a string at a newline, so later declarations can still apply. if (/[\n\r\f]/.test(token)) badString = true; return '""'; }, ); - // Semicolons in blocks can be part of a declaration's value. - if (badString || /[()[\]{}]/.test(declarations)) return false; + if (badString) return false; + // Semicolons in blocks are part of a declaration's value, so split only at depth zero. + const closers: string[] = []; + const parts: string[] = []; + let start = 0; + for (let index = 0; index < declarations.length; index++) { + const char = declarations[index]; + if (char === "(") closers.push(")"); + else if (char === "[") closers.push("]"); + else if (char === "{") closers.push("}"); + else if (char === ")" || char === "]" || char === "}") { + if (closers.pop() !== char) return false; + } else if (char === ";" && closers.length === 0) { + parts.push(declarations.slice(start, index)); + start = index + 1; + } + } + if (closers.length > 0) return false; + parts.push(declarations.slice(start)); let hidden = false; - for (const [declaration] of declarations.matchAll(/[^;]+/g)) { + for (const declaration of parts) { const match = /^[\t\n\f\r ]*(display|all)[\t\n\f\r ]*:([^!]+)![\t\n\f\r ]*important[\t\n\f\r ]*$/i.exec( declaration, diff --git a/apps/server/src/provider/userInputAttachments.test.ts b/apps/server/src/provider/userInputAttachments.test.ts index 10adf6fa989b..c020d8affc19 100644 --- a/apps/server/src/provider/userInputAttachments.test.ts +++ b/apps/server/src/provider/userInputAttachments.test.ts @@ -1274,6 +1274,11 @@ describe("question answer paths", () => { "fig.svg": 'Standalone SVG metadata' + 'Superseded gate' + + 'Closed ferry berth' + + 'Old pier' + + 'Harbour light' + + 'Ferry timetable' + + 'Old legend' + 'Standalone chart', }, expected: [ @@ -1282,6 +1287,8 @@ describe("question answer paths", () => { "Q4 Revenue", "Foreign metadata", "Prefixed label", + "Harbour light", + "Ferry timetable", "Standalone chart", ], absent: [ @@ -1291,6 +1298,9 @@ describe("question answer paths", () => { "Prefixed SVG metadata", "Standalone SVG metadata", "Superseded gate", + "Closed ferry berth", + "Old pier", + "Old legend", ], }, {