-
Notifications
You must be signed in to change notification settings - Fork 229
fix: resolve 4 bugs in termui #3592
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Reject hexadecimal entities longer than eight digits.
If the eight-digit cap is intentional, validate the full digit length and return 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);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match; | ||||||||||||
|
Comment on lines
+30
to
31
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 | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: node - <<'NODE'
const codePoint = Number.parseInt('FFFFFFF', 16);
console.log(Number.isFinite(codePoint)); // true
try {
String.fromCodePoint(codePoint);
} catch (error) {
console.log(error.name); // RangeError
}
NODERepository: Karanjot786/TermUI Length of output: 172 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate and inspect the reported file and surrounding parsing logic.
if [ -f examples/rss-reader/src/index.tsx ]; then
echo "== file exists =="
wc -l examples/rss-reader/src/index.tsx
echo "== relevant lines =="
sed -n '1,80p' examples/rss-reader/src/index.tsx | cat -n
else
echo "examples/rss-reader/src/index.tsx not found"
fd -p 'index.tsx$' .
fi
echo "== entity-related symbols =="
rg -n "parseInt|fromCodePoint|entity|&#|\\?\\?=" examples/rss-reader/src/index.tsx examples/rss-reader/src 2>/dev/null || trueRepository: Karanjot786/TermUI Length of output: 5093 🌐 Web query:
💡 Result: The JavaScript method String.fromCodePoint throws a RangeError if a provided argument is not an integer, is less than 0, or is greater than 0x10FFFF [1][2][3]. The range 0x0000 to 0x10FFFF encompasses all valid Unicode code points [1][4]. Notably, the values 0xD800 through 0xDFFF, which correspond to surrogate code units in UTF-16, are technically valid Unicode code points [5]. Consequently, String.fromCodePoint accepts values in the 0xD800–0xDFFF range and will successfully convert them into their corresponding characters [5]. It does not throw a RangeError for these values, despite them not being "Unicode scalar values" (which exclude surrogates) [5]. The method is designed to allow the creation of strings from these values, meaning it can technically produce strings containing unpaired surrogates [5]. RangeError is strictly reserved for values outside the defined Unicode codespace (i.e., < 0 or > 0x10FFFF) or non-integral values [1][2][3]. Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== behavioral probe =="
node - <<'NODE'
function decodeEntities(value) {
const entities = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
return value.replace(/&(`#x`?[0-9a-fA-F]+|[a-zA-Z]+);/g, (match, entity) => {
if (entity.startsWith('`#x`')) {
const codePoint = Number.parseInt(entity.slice(2, 10), 16);
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
}
if (entity.startsWith('#')) {
const codePoint = Number.parseInt(entity.slice(1), 10);
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
}
return entities[entity.toLowerCase()] ?? match;
});
}
const inputs = ['&`#xFFFFFFF`;', '&`#x110000`;', '&`#55349`;&`#56320`;', '&`#21474`;'];
for (const input of inputs) {
console.log(`${input}:`);
try {
console.log(` -> ${decodeEntities(input)}`);
} catch (error) {
console.log(` -> error: ${error.name}: ${error.message}`);
}
}
NODERepository: Karanjot786/TermUI Length of output: 351 🌐 Web query:
💡 Result: TermUI is a TypeScript/JavaScript framework for building terminal applications [1]. Its core architecture is split into several packages, primarily Citations:
Validate Unicode code points before calling
Proposed fix Fix lines 29 and 34- return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
+ const isCodePoint = Number.isInteger(codePoint) && codePoint >= 0 && codePoint <= 0x10ffff;
+ return isCodePoint ? String.fromCodePoint(codePoint) : match;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
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 | 🟡 Minor | ⚡ Quick win
Apply
Number.EPSILONbefore scaling the percentage.setValueallows values such as0.145. The current expression can keep the result just below14.5, so the label can render14%instead of15%.Proposed fix
Add a regression test for the
0.145boundary.📝 Committable suggestion
🤖 Prompt for AI Agents