Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed issue of Improper encoding of curly braces in Request Sample #2780

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/elements-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-core",
"version": "9.0.0",
"version": "9.0.1",
"sideEffects": [
"web-components.min.js",
"src/web-components/**",
Original file line number Diff line number Diff line change
@@ -16,8 +16,34 @@ export const convertRequestToSample = async (
} else {
converted = converted || null;
}

// This code checks if the 'converted' string is a valid string, decodes any URL-encoded curly braces in it,
// and then iterates through each query parameter in the request's query string. For any query parameter
// containing curly braces, it selectively encodes the characters while preserving the curly braces.
// The decoded query string is then replaced with the fully encoded query in the 'converted' string to ensure
// proper encoding of the query parameters while keeping curly braces intact.

if (typeof converted === 'string') {
converted = converted.replace(/%7B/g, '{').replace(/%7D/g, '}');

if (request?.queryString?.length) {
for (const query of request.queryString) {
if (query?.value.includes('{') || query?.value.includes('}')) {
let encodeValue = '';
for (const val of query?.value) {
if (val !== '{' && val !== '}') {
encodeValue += encodeURIComponent(val);
} else {
encodeValue += val;
}
}
const decodedQuery = `${query?.name}=${encodeValue}`;
const encodedQuery = `${query?.name}=${encodeURIComponent(query?.value)}`;

converted = converted.replace(decodedQuery, encodedQuery);
}
}
}
}

return converted;
2 changes: 1 addition & 1 deletion packages/elements-dev-portal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-dev-portal",
"version": "3.0.0",
"version": "3.0.1",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
4 changes: 2 additions & 2 deletions packages/elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements",
"version": "9.0.0",
"version": "9.0.1",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
@@ -63,7 +63,7 @@
]
},
"dependencies": {
"@stoplight/elements-core": "~9.0.0",
"@stoplight/elements-core": "~9.0.1",
"@stoplight/http-spec": "^7.1.0",
"@stoplight/json": "^3.18.1",
"@stoplight/mosaic": "^1.53.4",