-
Notifications
You must be signed in to change notification settings - Fork 232
fix: resolve 2 bugs #3376
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
base: main
Are you sure you want to change the base?
fix: resolve 2 bugs #3376
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 |
|---|---|---|
|
|
@@ -182,8 +182,8 @@ function _pathsEqual(a: number[], b: number[]): boolean { | |
|
|
||
| function _valuesEqual(a: string[], b: string[]): boolean { | ||
| if (a.length !== b.length) return false; | ||
| const sortedA = [...a].sort(); | ||
| const sortedB = [...b].sort(); | ||
| const sortedA = [...a].sort((a, b) => a - b); | ||
| const sortedB = [...b].sort((a, b) => a - b); | ||
|
Comment on lines
+185
to
+186
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 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Repository files of interest:\n'
git ls-files | rg '(^packages/ui/src/TreeSelect\.ts$|^scripts/build-registry\.ts$|^scripts/build-registry\.test\.ts$)' || true
printf '\n--- TreeSelect relevant excerpt ---\n'
nl -ba packages/ui/src/TreeSelect.ts | sed -n '160,205p'
printf '\n--- build-registry relevant excerpt ---\n'
nl -ba scripts/build-registry.ts | sed -n '1,80p'
printf '\n--- tests relevant excerpt if present ---\n'
if [ -f scripts/build-registry.test.ts ]; then
nl -ba scripts/build-registry.test.ts | sed -n '100,155p'
fi
printf '\n--- type usage around sorted values ---\n'
rg -n "sort\\(|valuesEqual|collectDeps|deps|deps" packages/ui/src/TreeSelect.ts scripts/build-registry.ts scripts/build-registry.test.ts || true
printf '\n--- Behavioral probe: runtime comparator results for strings ---\n'
node - <<'JS'
const tests = [
[['apple', 'banana', 'cherry'], 'strings'],
[['001', '1', '01'], 'leading-zeros strings'],
[['0', '2', '1'], 'digit strings'],
[['0.1', '0.2', '1'], 'decimal strings'],
[['', 'apple'], 'string/empty'],
[['a', 1], 'mixed string/number'],
];
for (const [arr, label] of tests) {
const a = [...arr].sort((a, b) => a - b);
const b = [...arr].sort((a, b) => String(a).localeCompare(String(b)));
console.log(`${label}: ${JSON.stringify([...arr])} -> numeric=${JSON.stringify(a)} lexical=${JSON.stringify(b)}`);
}
JSRepository: Karanjot786/TermUI Length of output: 350 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '--- TreeSelect relevant excerpt ---\n'
awk '{printf "%6d\t%s\n", NR, $0}' packages/ui/src/TreeSelect.ts | sed -n '160,205p'
printf '\n--- build-registry relevant excerpt ---\n'
awk '{printf "%6d\t%s\n", NR, $0}' scripts/build-registry.ts | sed -n '1,80p'
printf '\n--- tests relevant excerpt if present ---\n'
awk '{printf "%6d\t%s\n", NR, $0}' scripts/build-registry.test.ts | sed -n '100,155p'
printf '\n--- Search relevant usage ---\n'
rg -n "sort\\(|valuesEqual|collectDeps|deps|deps" packages/ui/src/TreeSelect.ts scripts/build-registry.ts scripts/build-registry.test.ts || true
printf '\n--- Behavioral probe: runtime comparator results for strings ---\n'
node - <<'JS'
const tests = [
[['apple', 'banana', 'cherry'], 'strings'],
[['001', '1', '01'], 'leading-zeros strings'],
[['0', '2', '1'], 'digit strings'],
[['0.1', '0.2', '1'], 'decimal strings'],
[['', 'apple'], 'string/empty'],
[['a', 1], 'mixed string/number'],
];
for (const [arr, label] of tests) {
const a = [...arr].sort((a, b) => a - b);
const b = [...arr].sort((a, b) => String(a).localeCompare(String(b)));
console.log(`${label}: ${JSON.stringify([...arr])} -> numeric=${JSON.stringify(a)} lexical=${JSON.stringify(b)}`);
}
JSRepository: Karanjot786/TermUI Length of output: 247 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- TreeSelect relevant excerpt ---'
awk '{printf "%6d\t%s\n", NR, $0}' packages/ui/src/TreeSelect.ts | sed -n '160,205p'
echo
echo '--- build-registry relevant excerpt ---'
awk '{printf "%6d\t%s\n", NR, $0}' scripts/build-registry.ts | sed -n '1,80p'
echo
echo '--- tests relevant excerpt if present ---'
awk '{printf "%6d\t%s\n", NR, $0}' scripts/build-registry.test.ts | sed -n '100,155p'
echo
echo '--- Search relevant usage ---'
rg -n "sort\(|valuesEqual|collectDeps|deps|deps" packages/ui/src/TreeSelect.ts scripts/build-registry.ts scripts/build-registry.test.ts || true
echo
echo '--- Behavioral probe: runtime comparator results for strings ---'
node - <<'JS'
const tests = [
[['apple', 'banana', 'cherry'], 'strings'],
[['001', '1', '01'], 'leading-zeros strings'],
[['0', '2', '1'], 'digit strings'],
[['0.1', '0.2', '1'], 'decimal strings'],
[['', 'apple'], 'string/empty'],
[['a', 1], 'mixed string/number'],
];
for (const [arr, label] of tests) {
const a = [...arr].sort((a, b) => a - b);
const b = [...arr].sort((a, b) => String(a).localeCompare(String(b)));
console.log(`${label}: ${JSON.stringify([...arr])} -> numeric=${JSON.stringify(a)} lexical=${JSON.stringify(b)}`);
}
JSRepository: Karanjot786/TermUI Length of output: 9926 Use string comparison for these comparators. The comparators are called on
📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| for (let i = 0; i < sortedA.length; i++) { | ||
| if (sortedA[i] !== sortedB[i]) return false; | ||
| } | ||
|
|
||
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Karanjot786/TermUI
Length of output: 2216
🌐 Web query:
MDN String.fromCodePoint valid Unicode code point RangeError code points range💡 Result:
The String.fromCodePoint static method in JavaScript expects one or more arguments, each representing a valid Unicode code point [1][2]. A valid Unicode code point is an integer within the inclusive range of 0 to 0x10FFFF (decimal 1,114,111) [1][3]. A RangeError is thrown if any of the provided arguments fail to meet these criteria [1][3]. Specifically, the method throws a RangeError in the following scenarios: - The value is not an integer (e.g., 3.14 or other non-integral numbers) [1][3][4]. - The value is less than 0 [1][3][4]. - The value is greater than 0x10FFFF [1][3][4]. - The value is NaN [3][5]. As defined in the ECMAScript specification, these checks are performed after the input is converted to a number [4][6]. If an argument is out of range or not an integral number, the operation fails and the RangeError is thrown [4][6].
Citations:
🌐 Web query:
MDN Number.parseInt radix overflow to Number.MAX_SAFE_INTEGER hex parsing💡 Result:
The
parseInt()(andNumber.parseInt()) function in JavaScript does not trigger an "overflow" or error when parsing a string that exceedsNumber.MAX_SAFE_INTEGER[1][2]. Instead, it parses the string and returns the closest representable Number value [1]. Because JavaScript numbers use IEEE 754 double-precision floating-point format, they can only represent integers exactly within the range of-(2^53 - 1)to2^53 - 1(Number.MAX_SAFE_INTEGER) [3]. If you parse a hexadecimal string that represents a value larger than this,parseInt()will return a rounded approximation of that value [1][2]. Key points regarding this behavior: 1. No Exception:parseInt()will not throw an error or returnNaNsimply because a number is larger thanNumber.MAX_SAFE_INTEGER[1][2]. 2. Precision Loss: Once the value exceeds the safe integer range, precision is lost. Subsequent integers may be rounded to the same representable floating-point number, making them indistinguishable during equality checks [2][3]. 3. Hexadecimal Parsing: When provided with a hex string (e.g., starting with0x),parseInt(string, 16)correctly interprets the digits but remains subject to the same floating-point limitations as any other number parsing [4][5]. 4. Recommended Alternative: If you need to work with integers larger thanNumber.MAX_SAFE_INTEGERwithout losing precision, use theBigInttype [3][5]. You can parse large hexadecimal strings usingBigInt("0x" + hexString)orBigInt(string)if the radix is handled appropriately [5]. For example: // This will result in precision loss const largeHex = "0x20000000000001"; // Greater than Number.MAX_SAFE_INTEGER const parsed = parseInt(largeHex, 16); console.log(parsed > Number.MAX_SAFE_INTEGER); // true console.log(parsed); // Returns the rounded Number representation // For accurate parsing, use BigInt const bigIntVal = BigInt(largeHex); console.log(bigIntVal); // Returns the exact BigInt valueCitations:
🏁 Script executed:
Repository: Karanjot786/TermUI
Length of output: 5435
Reject invalid numeric entities before decoding.
Number.isArrayFinite(codePoint)does not validate the Unicode range forString.fromCodePoint, so values above0x10FFFFthrowRangeErrorduring RSS text rendering. Accept only non-empty matches, parse the fullentity.slice(...)value, and keep the value in0through0x10FFFFinclusive before decoding.🤖 Prompt for AI Agents