Repository navigation
ref(service): Share parseJson, isObject, and httpError - #62
Merged
Merged
Conversation
`request-key.ts` and `usage.ts` each had a copy of `parseJson`, and
`json-strings.ts` had a third that also skips a byte order mark.
`usage.ts` and `secrets.ts` each had `isObject`. `bodies.ts` had
`httpError`, and `recorder.ts` and `secrets.ts` built the same error by
hand.
- `json-strings.ts` now has `parseJson` (no BOM skip), `parseJsonSkipBom`
(for `secrets.ts`, as before), and `isObject`.
- `errors.ts` now has `httpError`. `bodies.ts`, `recorder.ts`, and
`secrets.ts` use it.
The key keeps the parse without the BOM skip, so a body that starts with
a BOM keys as text, as before. `JSON.parse("")` throws, so the old
`body ? JSON.parse(body) : undefined` of `request-key.ts` gives the same
result. The pinned key tests pass without a change, and a randomized
compare of 30,000 bodies (JSON, BOM, cut JSON, forms, streams, thinking
blocks, known values) against main gives the same `keyRequest`,
`usageAttributes`, `redactRequest`, and `redactFields` results.
Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No behavior change.
parseJsoninjson-strings.ts. A separateparseJsonSkipBomskips a leading byte order mark, and onlysecrets.tsuses it, as before. The key code never skipped the BOM, so it still doesn't.isObjectis shared.httpErrormoved toerrors.ts.bodies.ts,recorder.tsandsecrets.tsuse it.Same output as main: a side-by-side run on about 24,000 cases (BOMs, empty and invalid bodies, scalars,
__proto__, lone surrogates,\uescapes, duplicate keys, form and event-stream content types) gave 0 differences inkeyRequest,usageAttributes,redactRequestWith,redactRequestUrl,redactFieldsand the learned credential list. The pinned key tests pass with no edits.Reviewed independently.
pnpm checkpasses and knip is clean.via @dcramer.
--
View Session [Sentry]