-
Notifications
You must be signed in to change notification settings - Fork 230
fix: resolve 4 bugs in termui #3713
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ function decodeEntities(value: string): string { | |
|
|
||
| return value.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (match, entity: string) => { | ||
| if (entity.startsWith('#x')) { | ||
| const codePoint = Number.parseInt(entity.slice(2), 16); | ||
| const codePoint = Number.parseInt(entity.slice(2, 10), 16); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
file="examples/rss-reader/src/index.tsx"
if ! rg -n 'codePoint\s*<=\s*0x10FFFF' "$file"; then
echo "Unicode range validation is missing." >&2
exit 1
fiRepository: Karanjot786/TermUI Length of output: 193 🏁 Script executed: #!/bin/bash
set -euo pipefail
file="examples/rss-reader/src/index.tsx"
echo "== file size =="
wc -l "$file"
echo "== target section =="
sed -n '1,80p' "$file" | cat -n
echo "== regex entity references to codePoint =="
rg -n 'codePoint|fromCodePoint|parseInt|entity|decode|replace' "$file"Repository: Karanjot786/TermUI Length of output: 4002 🌐 Web query:
💡 Result: The String.fromCodePoint method in JavaScript throws a RangeError when it is passed a value that is not a valid Unicode code point [1][2]. The valid range for Unicode code points is from 0 to 0x10FFFF (inclusive) [1][3]. Specifically, a RangeError is thrown if an argument meets any of the following conditions: - It is not an integer [1][2]. - It is less than 0 [1][2]. - It is greater than 0x10FFFF (which is 1114111 in decimal) [1][2]. This behavior is consistent with the ECMAScript specification, which mandates that if a code point provided to String.fromCodePoint is not an integral number or falls outside the 0 to 0x10FFFF range, a RangeError exception must be thrown [4][5][6][7]. Examples of invalid inputs that trigger this error include NaN, negative integers (e.g., -1), non-integers (e.g., 3.14), and values like Infinity or anything exceeding 0x10FFFF [1][2]. Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== JavaScript probe =="
node - <<'JS'
console.log(
'isFinite(0x110000)=', Number.isFinite(0x110000),
'isFinite(-1)=', Number.isFinite(-1),
'isFinite(+Infinity)=', Number.isFinite(Infinity)
);
for (const code of [-1, 0, 0x10FFFF, 0x110000, 0x110001]) {
try {
const out = String.fromCodePoint(code);
console.log(`fromCodePoint(${code})=ok ${JSON.stringify(out)}`);
} catch (error) {
console.log(`fromCodePoint(${code})=${error.name}: ${error.message}`);
}
}
JSRepository: Karanjot786/TermUI Length of output: 486 Validate the decoded code point range before
🤖 Prompt for AI Agents🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
file="examples/rss-reader/src/index.tsx"
if rg -n 'slice\(2,\s*10\)' "$file"; then
echo "Hexadecimal entities are still truncated." >&2
exit 1
fiRepository: Karanjot786/TermUI Length of output: 267 🏁 Script executed: #!/bin/bash
set -euo pipefail
file="examples/rss-reader/src/index.tsx"
printf '--- outline ---\n'
ast-grep outline "$file" --view expanded || true
printf '\n--- relevant source ---\n'
sed -n '1,80p' "$file" | cat -n
printf '\n--- deterministic behavior probe ---\n'
node - <<'JS'
const entities = ['&`#x41`;', '&`#x000000041`;', '&`#x110000`;'];
for (const entity of entities) {
const digits = entity.slice(2, 10);
const codePoint = Number.parseInt(digits, 16);
let result;
try {
result = String.fromCodePoint(codePoint);
} catch (er) {
result = `${er.name}: ${er.message}`;
}
console.log(JSON.stringify({entity, digits, codePoint, result}));
}
JSRepository: Karanjot786/TermUI Length of output: 247 🏁 Script executed: #!/bin/bash
set -euo pipefail
file="examples/rss-reader/src/index.tsx"
printf '%s\n' '--- outline ---'
ast-grep outline "$file" --view expanded || true
printf '%s\n' ''
printf '%s\n' '--- relevant source ---'
sed -n '1,120p' "$file" | cat -n
printf '%s\n' ''
printf '%s\n' '--- deterministic behavior probe ---'
node - <<'JS'
const cases = [
['&`#x41`;', 0x41],
['&`#x000000041`;', 0x41],
['&`#x00000000000000000000000000000000041`;2', 0x2 /* Number.parseInt ignores trailing junk */],
['&`#x110000`;', 0x110000],
['&`#x123456789`;', 0x23456789],
];
for (const [entity, expectedParsedFromSlice] of cases) {
const digits = entity.slice(2, 10);
const codePoint = Number.parseInt(digits, 16);
let result;
try {
result = String.fromCodePoint(codePoint);
} catch (er) {
result = er.name + ': ' + er.message;
}
console.log(JSON.stringify({entity, digits, codePoint, parsedMatchesExpectedSlice, expectedParsedFromSlice, result}));
}
JSRepository: Karanjot786/TermUI Length of output: 6724 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- deterministic behavior probe ---'
node - <<'JS'
const entities = [
['&`#x41`;', 0x41],
['&`#x000000041`;', 0x41],
['&`#x110000`;', 0x110000],
['&`#x123456789`;', 0x123456789],
];
for (const [entity, expectedParsedFromSlice] of entities) {
const digits = entity.slice(2, 10);
const codePoint = Number.parseInt(digits, 16);
let result;
try {
result = String.fromCodePoint(codePoint);
} catch (er) {
result = er.name + ': ' + er.message;
}
console.log(JSON.stringify({entity, digits, codePoint, expectedParsedFromSlice, result}));
}
JSRepository: Karanjot786/TermUI Length of output: 748 Reject overlong hexadecimal entities instead of truncating them. The regex allows more than eight hex digits, but Proposed fix- const codePoint = Number.parseInt(entity.slice(2, 10), 16);
+ const digits = entity.slice(2);
+ if (digits.length > 8) return match;
+ const codePoint = Number.parseInt(digits, 16);Proposed fix- const codePoint = Number.parseInt(entity.slice(2, 10), 16);
+ const digits = entity.slice(2);
+ if (digits.length > 8) return match;
+ const codePoint = Number.parseInt(digits, 16);🤖 Prompt for AI Agents |
||
| return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Karanjot786/TermUI
Length of output: 253
🏁 Script executed:
Repository: Karanjot786/TermUI
Length of output: 999
🏁 Script executed:
Repository: Karanjot786/TermUI
Length of output: 342
Use logical negation for the clear-form shortcut.
event.ctrl !is a postfix non-null assertion, so at runtime it is equivalent toevent.ctrl. This skips the clear form for plainc, whileevent.key === 'c' && event.ctrlis already handled as quit. Use!event.ctrland remove the forbidden type-assertion style.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines