Skip to content

Commit

Permalink
fix(preview): uri-encode search params
Browse files Browse the repository at this point in the history
This change applies basic URI encoding to knob keys/values in
`<iframe>` URL and torn-away window URL in preview.

Fixes storybookjs#11641.
  • Loading branch information
asudoh committed Jul 22, 2020
1 parent 28e65b0 commit 0fc8d47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,7 @@ export const WithDuplicateDecorator = () => {
return text('Text', 'Hello');
};
WithDuplicateDecorator.decorators = [withKnobs];

export const WithKnobValueToBeEncoded = () => {
return text('Text', '10% 20%');
};
5 changes: 4 additions & 1 deletion lib/ui/src/components/preview/utils/stringifyQueryParams.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const stringifyQueryParams = (queryParams: Record<string, string>) =>
Object.entries(queryParams).reduce((acc, [k, v]) => `${acc}&${k}=${v}`, '');
Object.entries(queryParams).reduce(
(acc, [k, v]) => `${acc}&${encodeURIComponent(k)}=${encodeURIComponent(v)}`,
''
);

0 comments on commit 0fc8d47

Please sign in to comment.