Skip to content

Commit 2649238

Browse files
committed
fix(cli): address PR review feedback on LaTeX renderer
- Remove convertLineBreaks from applyProseConversions so `\\` outside math delimiters is no longer rewritten to a newline. This protects Windows UNC paths (`\\server\share`) and escaped backslashes in code-like prose. LaTeX line breaks inside `$...$` / `$$...$$` are still handled by applyMathModeConversions. - Add `?? match` fallback to the MASK_PATTERN restore step so a stray PUA sentinel in user input can never cause "undefined" to leak into rendered output. - Add tests for Windows UNC paths and math-mode-only line breaks. Addresses review comments from @gemini-code-assist and @jacob314 on PR #25802.
1 parent f84ed9d commit 2649238

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

packages/cli/src/ui/utils/latexToUnicode.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ describe('convertLatexToUnicode', () => {
148148
expect(convertLatexToUnicode('word\\ boundary')).toBe('word boundary');
149149
});
150150

151-
it('converts \\\\ to a newline', () => {
152-
expect(convertLatexToUnicode('line1\\\\line2')).toBe('line1\nline2');
151+
it('converts \\\\ to a newline inside math mode', () => {
152+
// `\\` is a LaTeX line break in math/tabular contexts. Only convert
153+
// inside `$...$` — outside math this would mangle Windows UNC paths
154+
// (`\\server\share`) and escaped backslashes in code-like prose.
155+
expect(convertLatexToUnicode('$a\\\\b$')).toBe('a\nb');
156+
});
157+
158+
it('leaves \\\\ alone outside math mode', () => {
159+
expect(convertLatexToUnicode('line1\\\\line2')).toBe('line1\\\\line2');
153160
});
154161
});
155162

@@ -249,6 +256,14 @@ describe('convertLatexToUnicode', () => {
249256
);
250257
});
251258

259+
it('leaves Windows UNC paths alone (no line-break rewrite in prose)', () => {
260+
// `\\server\share\file` must NOT be rewritten to a newline. Line-break
261+
// conversion is restricted to math mode. See PR #25802.
262+
expect(convertLatexToUnicode('\\\\server\\share\\file')).toBe(
263+
'\\\\server\\share\\file',
264+
);
265+
});
266+
252267
it('leaves regex backslash escapes alone', () => {
253268
expect(convertLatexToUnicode('\\d+\\w*')).toBe('\\d+\\w*');
254269
});

packages/cli/src/ui/utils/latexToUnicode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ function applyProseConversions(text: string): string {
559559
out = convertTextFormatting(out);
560560
out = convertFractionsAndRoots(out);
561561
out = convertEscapedSpecials(out);
562-
out = convertLineBreaks(out);
562+
// Deliberately NOT running convertLineBreaks here: outside math delimiters
563+
// `\\` is far more likely to be a Windows UNC path (`\\server\share`) or an
564+
// escaped backslash in code-like prose than a LaTeX line break. Legitimate
565+
// LaTeX line breaks belong inside `$...$` or `$$...$$` and are handled by
566+
// applyMathModeConversions. See PR #25802 review.
563567
out = convertNamedCommands(out);
564568
out = convertPunctuationCommands(out);
565569
return out;

packages/cli/src/ui/utils/markdownParsingUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ const convertLatexPreservingSpans = (text: string): string => {
9696
const converted = convertLatexToUnicode(masked);
9797
return converted.replace(
9898
MASK_PATTERN,
99-
(_, i: string) => preserved[Number(i)],
99+
// Fallback to the literal match if the index is somehow out of range —
100+
// defensive against the unlikely case where the PUA sentinel appears in
101+
// user input. Without the fallback, replace would emit "undefined".
102+
(match, i: string) => preserved[Number(i)] ?? match,
100103
);
101104
};
102105

0 commit comments

Comments
 (0)