Skip to content

Commit

Permalink
fix: slugs are still broken when headings contain html (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Dec 18, 2020
1 parent bfdc537 commit 76c5e68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/render/slugify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function slugify(str) {
let slug = str
.trim()
.replace(/[A-Z]+/g, lower)
.replace(/<[^>\d]+>/g, '')
.replace(/<[^>]+>/g, '')
.replace(re, '')
.replace(/\s/g, '-')
.replace(/-+/g, '-')
Expand Down
15 changes: 15 additions & 0 deletions test/unit/render-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { removeAtag } = require('../../src/core/render/utils');

const { tree } = require(`../../src/core/render/tpl`);

const { slugify } = require(`../../src/core/render/slugify`);

// Suite
// -----------------------------------------------------------------------------
describe('core/render/utils', () => {
Expand Down Expand Up @@ -42,3 +44,16 @@ describe('core/render/tpl', () => {
);
});
});

describe('core/render/slugify', () => {
test('slugify()', () => {
const result = slugify(
`Bla bla bla <svg aria-label="broken" class="broken" viewPort="0 0 1 1"><circle cx="0.5" cy="0.5"/></svg>`
);
const result2 = slugify(
`Another <span style="font-size: 1.2em" class="foo bar baz">broken <span class="aaa">example</span></span>`
);
expect(result).toEqual(`bla-bla-bla-`);
expect(result2).toEqual(`another-broken-example`);
});
});

1 comment on commit 76c5e68

@vercel
Copy link

@vercel vercel bot commented on 76c5e68 Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.