Repository navigation
fix(terminal): end a url at CJK punctuation instead of swallowing it - #15240
Conversation
Terminal URL detection treated every non-ASCII character as part of the url, so Japanese or Chinese text written straight after one was absorbed into the link. A line like PR: https://github.com/org/repo/pull/12345(作成済み・マージ待ち) underlined the whole run and opened the annotation percent-encoded onto the end of the url, which 404s. The body terminator listed only ASCII codes, so nothing at or above 0x80 could end a url. Terminating on all non-ASCII is the obvious repair and is wrong: a url path may legitimately carry unencoded CJK, and the wrapped-url tests cover exactly that - a real multi-line url whose continuation row is a Chinese path segment. That repair was written first and broke four of them. The distinction is punctuation, not ASCII. Non-ASCII punctuation, symbols and separators end a url; letters do not. Full-width brackets, an ideographic space, a full-width comma and the katakana middle dot are prose; 文档 in a path is not. Adds the extraction test file the module never had, covering the reporter's three cases, the CJK-path case that must keep working, and ASCII behaviour as a regression guard. Closes #10571
📝 WalkthroughWalkthroughHTTP URL extraction now treats qualifying non-ASCII punctuation, symbols, and separators as URL terminators. Non-ASCII path characters, including CJK characters, remain valid URL content. Tests cover full-width punctuation, spaces, ASCII URL punctuation, CJK paths, and trailing ASCII punctuation. Merge Risk: 🟡 Moderate · up to The URL extraction change still absorbs some Unicode characters into links, which can make affected URLs open incorrectly. Merge should wait for this bounded correctness issue to be fixed. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 43f840eb-55e7-4fd3-8efd-fbe0380d8f09
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/terminal-http-url-extraction.test.tssrc/renderer/src/components/terminal-pane/terminal-http-url-extraction.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 2 remain after this review.
| function isNonAsciiUrlTerminator(code: number): boolean { | ||
| return code > 0x7e && NON_ASCII_URL_TERMINATOR.test(String.fromCharCode(code)) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
file='src/renderer/src/components/terminal-pane/terminal-http-url-extraction.ts'
test_file='src/renderer/src/components/terminal-pane/terminal-http-url-extraction.test.ts'
printf '%s\n' '--- target implementation ---'
cat -n "$file" | sed -n '1,230p'
printf '%s\n' '--- focused tests ---'
cat -n "$test_file" | sed -n '1,180p'
printf '%s\n' '--- related symbols and call sites ---'
rg -n -C 3 'isNonAsciiUrlTerminator|isHttpUrlBodyTerminator|NON_ASCII_URL_TERMINATOR|scanEnd|codePointAt|charCodeAt' \
"$file" "$test_file"Repository: stablyai/orca
Length of output: 12590
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
import re
from pathlib import Path
source = Path("src/renderer/src/components/terminal-pane/terminal-http-url-extraction.ts").read_text()
test_source = Path("src/renderer/src/components/terminal-pane/terminal-http-url-extraction.test.ts").read_text()
# Model the exact code path without importing or executing repository code.
terminator = re.compile(r"[\W]", re.UNICODE) # placeholder for reporting only
print("Target contains charCodeAt:", "charCodeAt" in source)
print("Target contains codePointAt:", "codePointAt" in source)
print("Target contains fromCharCode:", "fromCharCode" in source)
print("Target contains fromCodePoint:", "fromCodePoint" in source)
print("Target contains White_Space:", "White_Space" in source)
print("Target contains property Z:", r"\p{Z}" in source)
print("Tests contain supplementary-plane case:", "💥" in test_source)
print("Tests contain U+0085 case:", r"\u0085" in test_source)
PY
node - <<'JS'
const re = /[\p{P}\p{S}\p{Z}]/u;
const cases = [
["💥", [..."💥"][0].codePointAt(0)],
["U+0085", "\u0085", "\u0085".codePointAt(0)],
["U+00A0", "\u00a0", "\u00a0".codePointAt(0)],
["U+2028", "\u2028", "\u2028".codePointAt(0)],
];
for (const entry of cases) {
const label = entry[0];
const value = entry.length === 2 ? entry[1] : entry[1];
const codePoint = value.codePointAt(0);
const oldInput = String.fromCharCode(codePoint);
const newInput = String.fromCodePoint(codePoint);
console.log(JSON.stringify({
label,
codePoint: `U+${codePoint.toString(16).toUpperCase()}`,
oldCodeUnitInput: JSON.stringify(oldInput),
oldMatches: re.test(oldInput),
fullCodePointInput: JSON.stringify(newInput),
fullCodePointMatches: re.test(newInput),
whiteSpaceMatches: /[\p{P}\p{S}\p{White_Space}]/u.test(newInput),
}));
}
JSRepository: stablyai/orca
Length of output: 1074
🏁 Script executed:
#!/bin/bash
set -eu
node - <<'JS'
const oldRe = /[\p{P}\p{S}\p{Z}]/u;
const newRe = /[\p{P}\p{S}\p{White_Space}]/u;
for (const [label, value] of [
["💥", "💥"],
["U+0085", "\u0085"],
["U+00A0", "\u00a0"],
["U+2028", "\u2028"],
]) {
const codePoint = value.codePointAt(0);
const oldCodeUnitInput = String.fromCharCode(codePoint);
const fullCodePointInput = String.fromCodePoint(codePoint);
console.log(JSON.stringify({
label,
codePoint: `U+${codePoint.toString(16).toUpperCase()}`,
oldCodeUnitInput: JSON.stringify(oldCodeUnitInput),
oldMatchesOldInput: oldRe.test(oldCodeUnitInput),
fullCodePointInput: JSON.stringify(fullCodePointInput),
oldMatchesFullCodePoint: oldRe.test(fullCodePointInput),
whiteSpaceMatchesFullCodePoint: newRe.test(fullCodePointInput),
}));
}
JSRepository: stablyai/orca
Length of output: 912
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
for name in (
"src/renderer/src/components/terminal-pane/terminal-http-url-extraction.ts",
"src/renderer/src/components/terminal-pane/terminal-http-url-extraction.test.ts",
):
lines = Path(name).read_text().splitlines()
print(f"--- {name} ({len(lines)} lines) ---")
for number, line in enumerate(lines, 1):
if name.endswith(".ts") and not name.endswith(".test.ts") and 120 <= number <= 180:
print(f"{number}: {line}")
if name.endswith(".test.ts") and number <= 100:
print(f"{number}: {line}")
PY
node - <<'JS'
const oldTerminator = (code) =>
code <= 0x7e ? false : /[\p{P}\p{S}\p{Z}]/u.test(String.fromCharCode(code));
const newTerminator = (code) =>
code <= 0x7e ? false : /[\p{P}\p{S}\p{White_Space}]/u.test(String.fromCodePoint(code));
function scan(text, useNew) {
const terminator = useNew ? newTerminator : oldTerminator;
let index = 0;
while (index < text.length) {
const code = useNew ? text.codePointAt(index) : text.charCodeAt(index);
if (terminator(code)) return index;
index += useNew && code > 0xffff ? 2 : 1;
}
return text.length;
}
for (const suffix of ["💥text", "\u0085text", "\u00a0text", "\u2028text"]) {
const input = "https://example.com/a" + suffix;
console.log(JSON.stringify({
suffix: JSON.stringify(suffix),
oldStop: scan(input.slice("https://example.com/a".length), false),
newStop: scan(input.slice("https://example.com/a".length), true),
}));
}
JSRepository: stablyai/orca
Length of output: 3921
Scan URL terminators by Unicode code point.
The current scan includes 💥text and \u0085text in the extracted URL. Use codePointAt/fromCodePoint, advance by the code-point width, and replace \p{Z} with \p{White_Space}. Add regressions for both inputs.
📍 Affects 2 files
src/renderer/src/components/terminal-pane/terminal-http-url-extraction.ts#L150-L151(this comment)src/renderer/src/components/terminal-pane/terminal-http-url-extraction.test.ts#L30-L33
…tablyai#15240) Terminal URL detection treated every non-ASCII character as part of the url, so Japanese or Chinese text written straight after one was absorbed into the link. A line like PR: https://github.com/org/repo/pull/12345(作成済み・マージ待ち) underlined the whole run and opened the annotation percent-encoded onto the end of the url, which 404s. The body terminator listed only ASCII codes, so nothing at or above 0x80 could end a url. Terminating on all non-ASCII is the obvious repair and is wrong: a url path may legitimately carry unencoded CJK, and the wrapped-url tests cover exactly that - a real multi-line url whose continuation row is a Chinese path segment. That repair was written first and broke four of them. The distinction is punctuation, not ASCII. Non-ASCII punctuation, symbols and separators end a url; letters do not. Full-width brackets, an ideographic space, a full-width comma and the katakana middle dot are prose; 文档 in a path is not. Adds the extraction test file the module never had, covering the reporter's three cases, the CJK-path case that must keep working, and ASCII behaviour as a regression guard. Closes stablyai#10571
…tablyai#15240) Terminal URL detection treated every non-ASCII character as part of the url, so Japanese or Chinese text written straight after one was absorbed into the link. A line like PR: https://github.com/org/repo/pull/12345(作成済み・マージ待ち) underlined the whole run and opened the annotation percent-encoded onto the end of the url, which 404s. The body terminator listed only ASCII codes, so nothing at or above 0x80 could end a url. Terminating on all non-ASCII is the obvious repair and is wrong: a url path may legitimately carry unencoded CJK, and the wrapped-url tests cover exactly that - a real multi-line url whose continuation row is a Chinese path segment. That repair was written first and broke four of them. The distinction is punctuation, not ASCII. Non-ASCII punctuation, symbols and separators end a url; letters do not. Full-width brackets, an ideographic space, a full-width comma and the katakana middle dot are prose; 文档 in a path is not. Adds the extraction test file the module never had, covering the reporter's three cases, the CJK-path case that must keep working, and ASCII behaviour as a regression guard. Closes stablyai#10571
Space-less languages glue particles onto paths (README.mdへ). Widen
path classes with \p{L} for mid-path CJK (stablyai#13396) and trim non-ASCII
letters after an ASCII extension so the particle is not part of the
link (stablyai#15240 symmetry).
…ary module Move non-ASCII prose boundary from terminal-http-url-extraction into src/shared/non-ascii-terminal-text-boundary.ts and wire file-link trim through the same module (stablyai#15240 mirror).
…tablyai#15240) Terminal URL detection treated every non-ASCII character as part of the url, so Japanese or Chinese text written straight after one was absorbed into the link. A line like PR: https://github.com/org/repo/pull/12345(作成済み・マージ待ち) underlined the whole run and opened the annotation percent-encoded onto the end of the url, which 404s. The body terminator listed only ASCII codes, so nothing at or above 0x80 could end a url. Terminating on all non-ASCII is the obvious repair and is wrong: a url path may legitimately carry unencoded CJK, and the wrapped-url tests cover exactly that - a real multi-line url whose continuation row is a Chinese path segment. That repair was written first and broke four of them. The distinction is punctuation, not ASCII. Non-ASCII punctuation, symbols and separators end a url; letters do not. Full-width brackets, an ideographic space, a full-width comma and the katakana middle dot are prose; 文档 in a path is not. Adds the extraction test file the module never had, covering the reporter's three cases, the CJK-path case that must keep working, and ASCII behaviour as a regression guard. Closes stablyai#10571
Closes #10571.
Terminal URL detection treated every non-ASCII character as part of the url, so Japanese or Chinese text written straight after one was absorbed into the link:
underlined the whole run, and ⌘-click opened the annotation percent-encoded onto the end of the url, which 404s.
Root cause
isHttpUrlBodyTerminator(terminal-http-url-extraction.ts) listed only ASCII code points, so nothing at or above0x80could ever end a url — not full-width brackets, not an ideographic space, not、,。or・.The obvious fix is wrong, and I shipped it first
RFC 3986 says URIs are ASCII, so "terminate on any non-ASCII" looks correct. It made all three reported cases pass — and broke four existing tests:
Those tests are right. A url path may legitimately carry unencoded CJK, and
edge-wrapped-terminal-http-links.test.ts:352deliberately covershttps://example.com/…文档/路径wrapped across rows. Terminating on non-ASCII would have fixed one CJK bug by creating another.The distinction is punctuation, not ASCII. Non-ASCII punctuation, symbols and separators end a url; letters do not. Full-width brackets, an ideographic space, a full-width comma and the katakana middle dot are prose.
文档in a path is not.Behaviour
…/12345(作成済み・マージ待ち)(詳細は「https://example.com/docs」を参照」…/a (全角スペース区切り)…/a、次へ、https://example.com/文档/路径https://example.com/a_b-c?d=1&e=2#fhttps://example.com/a..still trimmedASCII handling is untouched — the existing explicit ASCII lists still run, so this cannot change behaviour for a url with no non-ASCII near it.
Tests
terminal-http-url-extraction.tshad no test file of its own; this adds one, covering the reporter's three cases, the CJK-path case that must keep working, and ASCII behaviour as a regression guard.Note
This is the mirror image of #13396, where file link detection truncated at the first non-Latin character so CJK paths never opened. Different module, opposite failure, same underlying gap: neither had a considered rule for where non-ASCII belongs in a path.