Skip to content

fix: drop the NUL byte from shortcutKey and add it to the default export - #1

Merged
giaBaoJS merged 1 commit into
mainfrom
fix/shortcut-key-default-export
Sep 1, 2026
Merged

fix: drop the NUL byte from shortcutKey and add it to the default export#1
giaBaoJS merged 1 commit into
mainfrom
fix/shortcut-key-default-export

Conversation

@giaBaoJS

@giaBaoJS giaBaoJS commented Sep 1, 2026

Copy link
Copy Markdown
Owner

The NUL byte

src/index.tsx line 42 contained a literal U+0000 inside the template
literal that shortcutKey() builds its separator from, where a space was
clearly meant:

return `${item.id}<NUL>{${sortedData}}`;

It looks like a space in an editor. It is not one.

It reaches users. shortcutKey is documented public API
(docs/API.md), and yarn prepare copies the byte straight into
lib/module/index.js, which is main and the default export condition.
Every key handed back to a caller therefore carries a control character:
a problem for anything that logs it, JSON-encodes it, uses it as a React
key, or writes it to a store that rejects NUL bytes, such as a Postgres
text column.

It also made the entry point unreviewable. Git classified
src/index.tsx as binary (git ls-files --eol reports i/-text w/-text),
so any diff of the file rendered as Binary files differ, and git blame,
grep and GitHub code search all returned nothing for it. This PR's own
diff of that file still shows as binary because the parent blob is; it
renders as normal text from the next change onwards.

The fix is the single character that was intended.

shortcutKey missing from the default export

README.md states that every function is reachable both as a named export
and on the default export. shortcutKey was the only one that was not, so:

import AppShortcuts from '@giabaojs/react-native-app-shortcuts';
AppShortcuts.shortcutKey(item); // TypeError: not a function

Tests

Two added to src/__tests__/shortcuts.test.ts:

  • the key holds no control characters, and equals a {"x":"1"};
  • the default export carries every function the module exports by name,
    derived from the module itself rather than a hand-kept list, so a future
    export cannot drift out of it unnoticed.

Both were confirmed to fail against the unfixed source, each against only
its own fix, and to pass once restored. yarn lint, yarn typecheck,
yarn test and yarn prepare are all green, and the rebuilt
lib/module/index.js no longer contains the byte.

src/index.tsx held a literal U+0000 where shortcutKey builds its
separator, so every key came out as "id<NUL>{...}" instead of "id {...}".
That has two consequences:

* The byte reaches consumers. shortcutKey is documented public API and
  the same string is baked into lib/module/index.js, so anything that
  logs the key, stores it, or uses it as a React key carries a control
  character it never asked for.
* Git classified src/index.tsx as binary, so every diff of the package
  entry point rendered as "Binary files differ" and blame, grep and code
  search all failed on it. That clears once this lands, because the new
  blob is plain text.

shortcutKey is also added to the default export. README.md states that
every function is reachable both as a named export and on the default
export, and this was the one that was not, so
`import AppShortcuts from '@giabaojs/react-native-app-shortcuts'` followed
by `AppShortcuts.shortcutKey(item)` threw a TypeError.

Both are covered: one test asserts the key holds no control characters,
the other derives the expected default export from the module's own named
function exports so a later addition cannot silently drift again.
@giaBaoJS
giaBaoJS merged commit 5f2b78c into main Sep 1, 2026
5 checks passed
@giaBaoJS
giaBaoJS deleted the fix/shortcut-key-default-export branch September 1, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant