Skip to content

fix(openapi-parser): strip a leading UTF-8 BOM before JSON.parse in normalize - #10792

Merged
hanspagel merged 3 commits into
scalar:mainfrom
b84330808:fix/openapi-parser-utf8-bom
Nov 2, 2026
Merged

hanspagel merged 3 commits into
scalar:mainfrom
b84330808:fix/openapi-parser-utf8-bom

Conversation

@b84330808

@b84330808 b84330808 commented Oct 30, 2026 •

Copy link
Copy Markdown

Problem

@scalar/openapi-parser maintained its own normalize(), separate from the one in @scalar/json-magic that #9107 fixed. JSON saved with a leading UTF-8 BOM was rejected, so an otherwise valid API description could fail in validate(), dereference(), or upgrade().

For example, save this document as UTF-8 with a BOM:

{
  "openapi": "3.1.0",
  "info": { "title": "Example", "version": "1.0.0" },
  "paths": {}
}

Previously, validate(await readFile('openapi.json', 'utf8')) rejected the document. It now parses and validates successfully.

Solution

Import and re-export @scalar/json-magic/helpers/normalize directly, removing the parser's duplicate normalizer entirely. This keeps BOM handling and JSON/YAML parsing in one place. Objects and filesystems retain their identity.

The exported helper now has the shared signature (content: unknown) => unknown. TypeScript callers must narrow its result before accessing properties.

Normalization also adopts the shared helper's handling of malformed JSON arrays: inputs such as [{foo: "bar"}] return undefined instead of falling back to YAML parsing.

Ticket

See #9097

@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a371fa1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@scalar/openapi-parser Patch
scalar-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

b84330808 and others added 2 commits November 2, 2026 15:35
…ormalize

JSON documents saved with a UTF-8 BOM (common on Windows) made normalize()
return undefined, so validate(), dereference() and upgrade() reported
"Can't find JSON, YAML or filename in data." This mirrors the fix already
made in @scalar/json-magic (scalar#9107).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hanspagel
hanspagel force-pushed the fix/openapi-parser-utf8-bom branch from c2f4999 to 91701a7 Compare November 2, 2026 14:38

@hanspagel hanspagel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks! I just made it use normalize from the json-magic package

@hanspagel
hanspagel enabled auto-merge (squash) November 2, 2026 15:04
@hanspagel
hanspagel temporarily deployed to production-netlify November 2, 2026 15:05 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify November 2, 2026 15:05 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify November 2, 2026 15:05 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify November 2, 2026 15:05 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify November 2, 2026 15:05 — with GitHub Actions Inactive
@hanspagel
hanspagel merged commit 5beb1d6 into scalar:main Nov 2, 2026
33 checks passed
@scalar-release-bot scalar-release-bot Bot mentioned this pull request Nov 2, 2026

This branch was previously deployed

1 inactive deployment
production-netlify — a371fa1d Deployed Nov 2, 2026 by hanspagel via test-e2e-scalar-app #4106
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.

2 participants