fix(samples): correct base64url encoding to prevent crash #10615
+8
−1
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.
Description
This PR fixes a TypeError: Unknown encoding: base64url that occurs when the UI tries to generate a sample for a schema with contentEncoding: base64url.
The encodeBase64Url helper function was incorrectly passing the string "base64url" directly to Buffer.toString(), which is not a valid encoding and causes a crash.
This fix changes the function to:
Call the working encodeBase64 function first.
Manually replace the +, /, and = characters to correctly conform to the base64url specification.
Motivation and Context
This change is required to fix a bug that crashes the UI when trying to render a valid OpenAPI 3.1 schema.
Fixes #10613
How Has This Been Tested?
I manually tested this fix using the following steps:
Created a new spec file (dev-helpers/bug-spec.yml) with the schema provided in issue #10613.
Ran the development server using npm run dev.
Loaded the spec file in the browser at http://localhost:3200.
Opened the developer console and expanded the /authorize endpoint.
Confirmed the TypeError: Unknown encoding: base64url was thrown.
Applied the code fix to encodeBase64Url.js.
Hard-refreshed the browser.
Expanded the /authorize endpoint again and confirmed the error was gone and the UI rendered the parameters correctly.
Ran the unit test suite (npm test) and confirmed all existing tests pass.
Screenshots (if appropriate):
Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests