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

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

🏁 Script executed:

#!/bin/bash
set -euo pipefail

node <<'NODE'
const codePoint = Number.parseInt('FFFFFFFF'.slice(0, 8), 16);
try {
  String.fromCodePoint(codePoint);
  process.exit(1);
} catch (error) {
  if (!(error instanceof RangeError)) throw error;
}
NODE

Repository: Karanjot786/TermUI

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the target file and nearby entity-decoding logic.
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
else
  echo "missing examples/rss-reader/src/index.tsx"
  git ls-files | rg 'examples/rss-reader/src/index\.tsx|rss-reader' || true
fi

# Behavioral probe for Number.parseInt/Number.isFinite/String.fromCodePoint without executing repo code.
node <<'NODE'
const inputs = ['&`#xFFFFFFFF`;', '&`#x10FFFF00`;', '&`#x10FFFF`;', '&`#x110000`;', '&`#x012345678ABC`;'];
for (const entity of inputs) {
  const matched = entity.match(/^&`#x`([0-9A-Fa-f]+);$/);
  const codePoint = Number.parseInt(entity.slice(2, 10), 16);
  let s;
  let errClass;
  try {
    s = String.fromCodePoint(codePoint);
  } catch (error) {
    errClass = error.constructor.name;
  }
  console.log(JSON.stringify({
    entity,
    matched: matched && matched[1],
    parsedSlice8: codePoint,
    finite: Number.isFinite(codePoint),
    exceedsMaxPlane: matched && matched[1] ? Number.parseInt(matched[1], 16) > 0x10FFFF : null,
    parsedFull: matched ? Number.parseInt(matched[1], 16) : null,
    finiteFull: matched ? Number.isFinite(Number.parseInt(matched[1], 16)) : null,
    string: s,
    errorClass: errClass,
  }), null, 2);
}
NODE

Repository: Karanjot786/TermUI

Length of output: 3382


Reject invalid hexadecimal entities before decoding.

Hexadecimal entities that do not match exactly 1–8 hex digits cause Number.isFinite(...) to return false, so valid inputs such as &#x10FFFF; fall through to the replacement text. Use the captured hex substring as the parsed value and reject empty values before calling Number.parseInt.

🤖 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 30 - 31, Update the
entity-decoding logic around codePoint to parse the captured hexadecimal
substring rather than a fixed slice, reject empty values before calling
Number.parseInt, and continue returning the original match for invalid or
non-finite values while correctly decoding 1–8 hex digits such as &`#x10FFFF`;.

}

Expand Down
2 changes: 1 addition & 1 deletion examples/todo-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CustomMultiProgress extends (MultiProgressClass as any) {
const value = Math.max(0, Math.min(1, item.value));
const filled = Math.round(barWidth * value);

const pct = Math.round(value * 100);
const pct = Math.round(value * 100 + Number.EPSILON);

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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

node <<'NODE'
const value = 0.145;
const current = Math.round(value * 100 + Number.EPSILON);
if (current !== 15) {
  process.exit(1);
}
NODE

Repository: Karanjot786/TermUI

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

cat -n examples/todo-app/src/index.ts | sed -n '90,115p'
node --version
node - <<'NODE'
console.log({
  value: 0.145,
  product: 0.145 * 100,
  current: Math.round(0.145 * 100 + Number.EPSILON),
  beforeScale: Math.round((0.145 + Number.EPSILON) * 100),
  scaledEpsilon: Math.round(0.145 * 100 + Number.EPSILON * 100),
});
NODE

Repository: Karanjot786/TermUI

Length of output: 1605


Scale the epsilon before rounding the percentage.

Adding Number.EPSILON after value * 100 leaves boundary values like 0.145 * 100 at 14.499999999999998, and Math.round(... + Number.EPSILON) rounds them to 14% instead of 15%. Scale the epsilon with the percentage instead.

Proposed fix
-            const pct = Math.round(value * 100 + Number.EPSILON);
+            const pct = Math.round(value * 100 + Number.EPSILON * 100);
📝 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 pct = Math.round(value * 100 + Number.EPSILON);
const pct = Math.round(value * 100 + Number.EPSILON * 100);
🤖 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/todo-app/src/index.ts` at line 107, Update the percentage
calculation in the progress-rendering logic around pct so Number.EPSILON is
multiplied by the same 100 scale as value before Math.round. Preserve the
existing conversion to an integer percentage while ensuring boundary values such
as 0.145 round to 15%.

const percentStr = ` ${pct}% `;
const showPct = barWidth >= percentStr.length;
const labelStart = showPct ? Math.floor((barWidth - percentStr.length) / 2) : -1;
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class WidgetGalleryApp extends Widget {
}

// Tab switching: 1-6
const num = parseInt(event.key);
const num = parseInt(event.key, 10);
if (num >= 1 && num <= 6) {
this._switchTab(num - 1);
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/MultiSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MultiSelect extends Widget {
}

get selectedOptions(): MultiSelectOption[] {
return [...this._checked].sort().map(i => this._options[i]);
return [...this._checked].sort((a, b) => a - b).map(i => this._options[i]);
}
selectNext(): void { if (this._options.length === 0) return; let n = this._cursorIndex + 1; while (n < this._options.length && this._options[n].disabled) n++; if (n < this._options.length) { this._cursorIndex = n; this.markDirty(); } }
selectPrev(): void { if (this._options.length === 0) return; let n = this._cursorIndex - 1; while (n >= 0 && this._options[n].disabled) n--; if (n >= 0) { this._cursorIndex = n; this.markDirty(); } }
Expand Down
Loading