Skip to content

fix: resolve 4 bugs in termui - #3584

Closed
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-18785
Closed

fix: resolve 4 bugs in termui#3584
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-18785

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Fixed default sort: .sort() coerces elements to strings, so [10, 9, 2] sorts as [10, 2, 9]; numeric comparator sorts correctly.
  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.
  • Replaced global isNaN with Number.isNaN: the global version coerces its argument, so isNaN('1') returns false while Number.isNaN is strict.
  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.

Type of Change

  • Bug fix (non-breaking change fixing an issue)

How Has This Been Tested?

  • Local manual testing

Checklist

  • My code follows the style guidelines
  • I have performed a self-review

Related Issue

Ref: #3583

Summary by CodeRabbit

  • Bug Fixes

    • Improved parsing of hexadecimal numeric entities to correctly limit the number of processed digits.
    • Improved validation of numeric choices in prompts.
  • Consistency

    • Dependency listings are now returned in a stable, sorted order.

@github-actions github-actions Bot added area:examples Example apps. area:ui @termuijs/ui labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes limit hexadecimal entity parsing to eight digits, use strict Number.isNaN validation for prompt choices, and sort collected dependencies with an explicit comparator.

Changes

Parsing and build corrections

Layer / File(s) Summary
Hexadecimal entity parsing
examples/rss-reader/src/index.tsx
Hexadecimal entities now parse at most eight digits before conversion.
Strict choice validation
packages/ui/src/prompts.ts
promptSelect now uses Number.isNaN to validate parsed choices.
Deterministic dependency ordering
scripts/build-registry.ts
collectDeps now sorts dependency specifiers with an explicit comparator.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug fixes, but it omits the required package section and uses Ref #3583`` instead of the required closing issue format. Add the missing template sections, identify the affected packages, and change the issue reference to Closes #3583``.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a bug-fix pull request and follows the required type: short description format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with 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.

Inline comments:
In `@examples/rss-reader/src/index.tsx`:
- 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.

In `@scripts/build-registry.ts`:
- 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.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 82161f41-a5df-4bd1-ad50-a02db8be3a18

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and b038b4e.

📒 Files selected for processing (3)
  • examples/rss-reader/src/index.tsx
  • packages/ui/src/prompts.ts
  • scripts/build-registry.ts

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.

Comment thread scripts/build-registry.ts
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:examples Example apps. area:ui @termuijs/ui type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant