encodeCbor() throws on objects with non-ASCII keys
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- backend
Research direction
Start in cbor/_common_encode.ts at calcEncodingSize() line 58 and compare object-key sizing with the string-value branch around line 34. Run the encodeCbor example with the non-ASCII key; done means it no longer throws while writing and successfully encodes the object.
Written by the indexing model from the issue text.
Description
encodeCbor() under-allocates its buffer when an object key contains multi-byte UTF-8 characters, then throws while writing:
import { encodeCbor } from "@std/cbor";
encodeCbor({ "é☃é☃é☃é☃": 1 });
// RangeError: offset is out of bounds
The cause is in calcEncodingSize(): object keys are sized as y.length bytes (cbor/_common_encode.ts:58), but encodeString() writes UTF-8, which needs up to 3 bytes per UTF-16 code unit. String values already account for this with x.length * 3 on line 34. Keys don't.
The fix looks like a one-liner: size keys the same way the value branch does. Happy to PR it.
Spotted by @bartlomieju while reviewing #7250.
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 685
- Avg merge
- 10d 11m
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from denoland/std
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·