Skip to content

fix: resolve 4 bugs in termui - #3622

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • 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: #3621

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat message parsing for lines containing only whitespace.
    • Corrected hexadecimal entity parsing in the RSS reader.
    • Improved numeric keyboard input handling in the widget gallery.
    • Added console logging when form-related asynchronous operations fail.

@github-actions github-actions Bot added area:examples Example apps. area:ui @termuijs/ui type:bug +10 pts. Bug fix. labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates parsing behavior in three examples and adds rejection logging to the form Promise workflow.

Changes

Input parsing corrections

Layer / File(s) Summary
Example input parsing fixes
examples/chat-app/src/index.tsx, examples/rss-reader/src/index.tsx, examples/widget-gallery/src/index.ts
Whitespace-only lines are treated as empty paragraphs. Hexadecimal entities are limited to eight digits. Numeric keys use radix 10.

Form error logging

Layer / File(s) Summary
Promise rejection logging
packages/ui/src/Form.ts
Rejected Promise.all operations are logged with console.error.

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 fixes and testing, but it omits the required package, GSSoC, and checklist sections and does not use the required issue-closing syntax. Add the missing template sections, identify the affected packages, complete the required checklist and GSSoC fields, and change “Ref: #3621” to “Closes #3621”.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the pull request as a bug fix and summarizes the four fixes in the changeset.
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 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.6)
packages/ui/src/Form.ts

File contains syntax errors that prevent linting: Line 142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.


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.

@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`:
- Around line 28-31: Update the entity-decoding callback to reject hexadecimal
entities containing more than eight digits before parsing, and require parsed
numeric values to be within 0x000000–0x10FFFF before calling
String.fromCodePoint. Apply the same upper-bound validation to decimal numeric
entities, returning the original match for invalid or out-of-range values so RSS
parsing continues safely.

In `@packages/ui/src/Form.ts`:
- Around line 141-142: Fix the Promise.all handling in Form by attaching the
rejection handler directly to the Promise.all expression, or replace it with a
try/catch around the existing await and rethrow after logging. Remove the
standalone .catch expression so packages/ui/src/Form.ts parses and compiles
successfully.
🪄 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: eae2489b-0900-4d26-823b-4c1315302bc8

📥 Commits

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

📒 Files selected for processing (4)
  • examples/chat-app/src/index.tsx
  • examples/rss-reader/src/index.tsx
  • examples/widget-gallery/src/index.ts
  • packages/ui/src/Form.ts

Comment on lines 28 to 31
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);
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;

Copy link
Copy Markdown

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

🌐 Web query:

Does JavaScript String.fromCodePoint throw RangeError for values greater than 0x10FFFF?

💡 Result:

Yes, the JavaScript String.fromCodePoint method throws a RangeError if any of the provided arguments are greater than 0x10FFFF [1][2]. According to the ECMAScript specification, String.fromCodePoint iterates through its arguments and performs a check to ensure each is a valid Unicode code point [3][4]. A value is considered invalid if it is not an integral number, is less than 0, or is greater than 0x10FFFF [3][4]. If any of these conditions are met, the method throws a RangeError exception [1][3]. This behavior is consistent across all modern JavaScript environments as defined by the ECMAScript standard [3][5][6][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the referenced file and decoding implementation.
if [ -f examples/rss-reader/src/index.tsx ]; then
  wc -l examples/rss-reader/src/index.tsx
  sed -n '1,80p' examples/rss-reader/src/index.tsx | cat -n
else
  echo "File examples/rss-reader/src/index.tsx not found"
  fd -i 'index\.tsx$' . | sed -n '1,40p'
fi

# Find any related tests or usages that may affect severity.
printf '\nSearch for decodeEntity/replace/unescape references:\n'
rg -n "decodeEntity|unescape|&`#x`?|`#x`|[0-9a-fA-F]+;|String\.fromCodePoint|parseInt" examples/rss-reader/src examples/rss-reader 2>/dev/null || true

# Read-only behavioral probe matching the relevant parser slice semantics.
node - <<'JS'
function decodeCurrent(value) {
  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;
    }
    return match;
  });
}
const inputs = [
  '&amp;',
  '&`#x61`;',
  '&`#x10ffff`;',
  '&`#x110000`;',
  '&`#x110000ffffff`;',
  '&`#110000`;',
];
for (const input of inputs) {
  try {
    console.log(JSON.stringify(input), '=>', JSON.stringify(decodeCurrent(input)));
  } catch (error) {
    console.log(JSON.stringify(input), 'THREW', error.name + ': ' + error.message);
  }
}
JS

Repository: Karanjot786/TermUI

Length of output: 5558


Reject overlong and invalid hexadecimal entities.

entity.slice(2, 10) can turn longer malformed entities into valid values or pass values above 0x10ffff to String.fromCodePoint, which throws RangeError and stops RSS parsing. Skip entities with more than eight hexadecimal digits before parsing, validate codePoint <= 0x10ffff before conversion, and apply the same range check to decimal numeric entities.

Proposed fix
 if (entity.startsWith('`#x`')) {
-  const codePoint = Number.parseInt(entity.slice(2, 10), 16);
-  return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
+  const digits = entity.slice(2);
+  if (digits.length > 8) return match;
+  const codePoint = Number.parseInt(digits, 16);
+  return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : match;
 }
🤖 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` around lines 28 - 31, Update the
entity-decoding callback to reject hexadecimal entities containing more than
eight digits before parsing, and require parsed numeric values to be within
0x000000–0x10FFFF before calling String.fromCodePoint. Apply the same
upper-bound validation to decimal numeric entities, returning the original match
for invalid or out-of-range values so RSS parsing continues safely.

Comment thread packages/ui/src/Form.ts
Comment on lines +141 to +142

.catch(err => console.error("Promise.all failed:", err)); No newline at end of file

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

Attach the rejection handler to the Promise expression.

Line 142 is a standalone .catch(...) expression. Biome reports a parse error, so packages/ui/src/Form.ts cannot compile. Attach .catch(...) directly to Promise.all(...), or use try/catch and rethrow after logging.

try {
    const results = await Promise.all(existingPromises);
    // Existing result handling.
} catch (err) {
    console.error("Promise.all failed:", err);
    throw err;
}
🧰 Tools
🪛 Biome (2.5.6)

[error] 142-142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.

(parse)

🪛 GitHub Actions: CI / 0_build-and-test.txt

[error] 142-142: @termuijs/ui build failed during tsup/esbuild: unexpected '.' at the standalone '.catch(err => console.error("Promise.all failed:", err));'. TypeScript also reported TS1128, TS1005, and TS2304 syntax errors. Command: bun run build.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: The @termuijs/ui build failed during tsup/esbuild: unexpected '.' in .catch(err => console.error("Promise.all failed:", err));. TypeScript also reported syntax errors (TS1128, TS1005, TS2304). Command: bun run build.

🤖 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 `@packages/ui/src/Form.ts` around lines 141 - 142, Fix the Promise.all handling
in Form by attaching the rejection handler directly to the Promise.all
expression, or replace it with a try/catch around the existing await and rethrow
after logging. Remove the standalone .catch expression so
packages/ui/src/Form.ts parses and compiles successfully.

Source: Linters/SAST tools

@saurabhhhcodes saurabhhhcodes mentioned this pull request Aug 6, 2026
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 2026
4 tasks
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