Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/rss-reader/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown

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

Reject overlong hexadecimal entities instead of truncating them.

The regular expression accepts any number of hexadecimal digits, but entity.slice(2, 10) keeps only the first eight. For example, A becomes U+0004 instead of A. Check the digit count before parsing and return match when the entity exceeds the eight-digit limit.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/rss-reader/src/index.tsx` at line 30, Update the entity-decoding
logic around codePoint to validate the hexadecimal digit count before parsing;
when the entity contains more than eight digits, return the original match
unchanged, otherwise parse the full permitted value without truncation.

return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function promptSelect<T = string>(options: SelectPromptOptions<T>): Promis
return;
}
const n = parseInt(trimmed, 10);
if (!isNaN(n) && n >= 1 && n <= choices.length) {
if (!Number.isNaN(n) && n >= 1 && n <= choices.length) {
rl.close();
resolve(choices[n - 1].value);
return;
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function collectDeps(content: string): string[] {
const deps = new Set<string>();
let m: RegExpExecArray | null;
while ((m = re.exec(content)) !== null) deps.add(m[1]!);
return [...deps].sort();
return [...deps].sort((a, b) => a - b);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

if rg -nF 'sort((a, b) => a - b)' scripts/build-registry.ts; then
  echo "Numeric comparator still used for string dependencies." >&2
  exit 1
fi

rg -n -A12 -B2 'collects unique sorted `@termuijs/`\* specifiers' scripts/build-registry.test.ts

Repository: Karanjot786/TermUI

Length of output: 256


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "--- scripts/build-registry.ts ---"
cat -n scripts/build-registry.ts

echo "--- relevant test section ---"
sed -n '110,150p' scripts/build-registry.test.ts | cat -n

echo "--- TypeScript version/config availability ---"
if [ -f package.json ]; then jq '.devDependencies.typescript, .scripts' package.json; fi
if [ -f tsconfig.json ]; then jq '.compilerOptions' tsconfig.json; fi

Repository: Karanjot786/TermUI

Length of output: 25168


Use a string comparator for dependency names.

collectDeps returns string[], so a - b is a TS2365 error. If type checking is skipped, the comparator evaluates to NaN, and sort does not guarantee alphabetical dependency order.

Proposed fix
-  return [...deps].sort((a, b)章 a - b);
+  return [...deps].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/build-registry.ts` at line 47, Update the sorting logic in
collectDeps to use a string comparator for the returned dependency names instead
of numeric subtraction, ensuring TypeScript compatibility and deterministic
alphabetical ordering.

Source: Coding guidelines

}

export function toSlug(name: string): string {
Expand Down
Loading