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

Core: support unicode chars in story IDs #5964

Merged
merged 3 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions examples/official-storybook/stories/core/unicode.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

storiesOf('Core|Unicode', module)
.add('😀', () => <p>❤️</p>)
.add('Кнопки', () => <p>нормальный</p>)
.add('바보', () => <p>🤷🏻‍♂️</p>);
4 changes: 3 additions & 1 deletion lib/router/src/tests/id.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ describe('toId', () => {
[
// name, kind, story, output
['handles simple cases', 'kind', 'story', 'kind--story'],
['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d-e--1-2-3'],
['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d😀e--1-2-3'],
['handles runs of non-url chars', 'a?&*b', 'story', 'a-b--story'],
['removes non-url chars from start and end', '?ab-', 'story', 'ab--story'],
['downcases', 'KIND', 'STORY', 'kind--story'],
['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'],
['korean', 'kind', '바보 (babo)', 'kind--바보-babo'],
].forEach(([name, kind, story, output]) => {
it(name, () => {
expect(toId(kind, story)).toBe(output);
Expand Down
2 changes: 1 addition & 1 deletion lib/router/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const splitPath = /\/([^/]+)\/([^/]+)?/;
export const sanitize = (string: string) => {
return string
.toLowerCase()
.replace(/[^a-z0-9-]/g, '-')
.replace(/[ '`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '-')
.replace(/-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
Expand Down