Skip to content

Commit

Permalink
Merge pull request #444 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v0.2.1
  • Loading branch information
robertu7 authored Sep 14, 2023
2 parents 98a6b24 + 9cf7af0 commit 6c20a9e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matters/matters-editor",
"version": "0.2.0",
"version": "0.2.1",
"description": "Editor for matters.news",
"author": "https://github.com/thematters",
"homepage": "https://github.com/thematters/matters-editor",
Expand Down
1 change: 0 additions & 1 deletion src/editors/extensions/readOnlyFigureEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export const ReadOnlyFigureEmbed = Node.create({
...(isCode ? [`embed-code`] : []),
].join(' ')

console.log({ url })

return [
'figure',
Expand Down
27 changes: 23 additions & 4 deletions src/transformers/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,27 @@ export const rehypeSanitizeOptions:
},
attributes: {
...defaultSchema.attributes,
a: ['href', 'ref', 'target', 'className', 'data*'],
br: ['className'],
a: [
// classes
['className', 'mention'],
'href',
'ref',
'target',
'data*',
],
br: [
// classes
['className', 'smart'],
],
img: ['src', 'srcSet', 'data*'],
audio: ['controls', 'data*', ['preload', 'metadata']],
source: ['src', 'type', 'data*'],
figure: [
// classes
['className', 'image', 'audio', 'embed', 'embed-code', 'embed-video'],
],
div: [
// classes
[
'className',
'player',
Expand All @@ -114,8 +126,15 @@ export const rehypeSanitizeOptions:
],
'data*',
],
h4: [['className', 'title']],
span: [['className', 'play', 'current', 'duration'], 'data*'],
h4: [
// classes
['className', 'title'],
],
span: [
// classes
['className', 'play', 'current', 'duration'],
'data*',
],
iframe: [
'src',
'allowFullScreen',
Expand Down
10 changes: 10 additions & 0 deletions src/transformers/sanitize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ const expectSanitizeHTML = (input: string, output: string) => {
/**
* Tests
*/
describe('Sanitization: custom', () => {
test('whitelist classes', () => {
expectSanitizeHTML('<a class="mention">pp</a>', '<a class="mention">pp</a>')
expectSanitizeHTML(
'<a class="styles_link__dKYrM">pp</a>',
'<a class="">pp</a>'
)
})
})

// via https://github.com/leizongmin/js-xss/blob/master/test/test_xss.js
describe('Sanitization: basic', () => {
test('unknown attributes', () => {
Expand Down

0 comments on commit 6c20a9e

Please sign in to comment.