diff --git a/examples/official-storybook/stories/core/__snapshots__/unicode.stories.storyshot b/examples/official-storybook/stories/core/__snapshots__/unicode.stories.storyshot new file mode 100644 index 000000000000..8d2102535065 --- /dev/null +++ b/examples/official-storybook/stories/core/__snapshots__/unicode.stories.storyshot @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Core|Unicode Кнопки 1`] = ` +

+ нормальный +

+`; + +exports[`Storyshots Core|Unicode 바보 1`] = ` +

+ 🤷🏻‍♂️ +

+`; + +exports[`Storyshots Core|Unicode 😀 1`] = ` +

+ ❤️ +

+`; diff --git a/examples/official-storybook/stories/core/unicode.stories.js b/examples/official-storybook/stories/core/unicode.stories.js new file mode 100644 index 000000000000..dada3c9f8332 --- /dev/null +++ b/examples/official-storybook/stories/core/unicode.stories.js @@ -0,0 +1,7 @@ +import React from 'react'; +import { storiesOf } from '@storybook/react'; + +storiesOf('Core|Unicode', module) + .add('😀', () =>

❤️

) + .add('Кнопки', () =>

нормальный

) + .add('바보', () =>

🤷🏻‍♂️

); diff --git a/lib/router/src/tests/id.test.js b/lib/router/src/tests/id.test.js index f65c6c414fe7..7f87b9015e43 100644 --- a/lib/router/src/tests/id.test.js +++ b/lib/router/src/tests/id.test.js @@ -4,10 +4,13 @@ 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'], + ['all punctuation', 'kind', 'unicorns,’–—―′¿`"<>()!.!!!{}[]%^&$*#&', 'kind--unicorns'], ].forEach(([name, kind, story, output]) => { it(name, () => { expect(toId(kind, story)).toBe(output); diff --git a/lib/router/src/utils.ts b/lib/router/src/utils.ts index a0659d3b31ab..dffd64cff86c 100644 --- a/lib/router/src/utils.ts +++ b/lib/router/src/utils.ts @@ -9,10 +9,11 @@ interface StoryData { const knownViewModesRegex = /(story|info)/; const splitPath = /\/([^/]+)\/([^/]+)?/; +// Remove punctuation https://gist.github.com/davidjrice/9d2af51100e41c6c4b4a export const sanitize = (string: string) => { return string .toLowerCase() - .replace(/[^a-z0-9-]/g, '-') + .replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '-') .replace(/-+/g, '-') .replace(/^-+/, '') .replace(/-+$/, '');