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

Improvement: Updated Sanitizer #1129

Open
wants to merge 77 commits into
base: master
Choose a base branch
from
Open
Changes from 9 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
e7b3407
update: GitHub workflow-dispatch
Batorian May 10, 2024
ffc7b3d
fix: separate app for testing
Batorian May 10, 2024
2c2dfac
fix: separate app for testing
Batorian May 10, 2024
0908469
fix: separate app for testing
Batorian May 10, 2024
3cdd2e8
fix: new css for chapter content
Batorian May 10, 2024
56bd026
fix: separate app for testing
Batorian May 10, 2024
ba6fd3a
branch: new test branch
Batorian May 15, 2024
eb4f65c
Enhancement: added more CSS
Batorian Jun 7, 2024
fb17400
merge
Batorian Jun 7, 2024
aab29b2
build
Batorian Jun 7, 2024
a3550c9
Enhancement: git build
Batorian Jun 9, 2024
8ddb3df
Fix: git build
Batorian Jun 9, 2024
49d0e17
Merge branch 'refs/heads/master' into dev
Batorian Jun 9, 2024
9a60eb2
merge
Batorian Jun 9, 2024
721ae34
Enhancement: added more CSS
Batorian Jun 18, 2024
4db628c
Merge branch 'refs/heads/prod' into dev
Batorian Jun 22, 2024
4aeec5e
dev: update build.yml
Batorian Jun 22, 2024
1c6122a
Merge branch 'LNReader:master' into dev
Batorian Jun 23, 2024
655f141
Merge branch 'LNReader:master' into dev
Batorian Jun 27, 2024
06d430a
Merge branch 'LNReader:master' into dev
Batorian Jun 30, 2024
60a5b24
Merge branch 'LNReader:master' into dev
Batorian Jul 6, 2024
d62ddce
dev: update sanitizer
Batorian Jul 6, 2024
111f7fe
sanitizer: updated sanitizer
Batorian Jul 6, 2024
6c8dddc
Merge branch 'LNReader:master' into dev
Batorian Jul 7, 2024
3d51ea3
Merge branch 'LNReader:master' into sanitizer
Batorian Jul 7, 2024
12a8357
dev: update index css
Batorian Jul 7, 2024
447a4f4
Merge remote-tracking branch 'origin/dev' into dev
Batorian Jul 7, 2024
459fdc6
dev: update sanitizer
Batorian Jul 7, 2024
57fa484
dev: update sanitizer
Batorian Jul 7, 2024
3b77018
sanitizer: update sanitizer
Batorian Jul 7, 2024
edadc7e
sanitizer: added more allowed tags
Batorian Jul 8, 2024
739d6ca
filter: fix filters
Batorian Jul 10, 2024
1f37be6
Merge branch 'LNReader:master' into dev
Batorian Jul 12, 2024
9fe44b6
Merge branch 'LNReader:master' into filter
Batorian Jul 12, 2024
7bb4034
Merge pull request #2 from Batorian/filter
Batorian Jul 12, 2024
5e65bea
Merge branch 'LNReader:master' into dev
Batorian Jul 13, 2024
af08890
Merge branch 'LNReader:master' into sanitizer
Batorian Jul 13, 2024
4e7f8f2
Merge branch 'LNReader:master' into dev
Batorian Jul 13, 2024
e415c09
Merge branch 'LNReader:master' into sanitizer
Batorian Jul 13, 2024
4bc77b4
Merge branch 'refs/heads/sanitizer' into dev
Batorian Jul 13, 2024
586821a
Merge branch 'refs/heads/prod' into dev
Batorian Jul 16, 2024
890b3dc
Merge branch 'refs/heads/prod' into sanitizer
Batorian Jul 16, 2024
5ecad66
Merge branch 'refs/heads/sanitizer' into dev
Batorian Jul 16, 2024
57644ca
progress-tracking: initial commit
Batorian Jul 18, 2024
1795d10
progress-tracking: implemented tracking
Batorian Jul 19, 2024
d4133b2
Merge branch 'LNReader:master' into dev
Batorian Jul 19, 2024
94b82d2
Merge branch 'LNReader:master' into progress-tracking
Batorian Jul 19, 2024
16b3557
Merge branch 'LNReader:master' into sanitizer
Batorian Jul 19, 2024
c5ce13c
Merge branch 'refs/heads/progress-tracking' into dev
Batorian Jul 19, 2024
5e0d85f
progress-tracking: update tracker
Batorian Jul 28, 2024
5bd919e
Merge branch 'refs/heads/progress-tracking' into dev
Batorian Jul 28, 2024
41a638b
progress-tracking: complete rework
Batorian Jul 29, 2024
6bec6ce
progress-tracking: improvements
Batorian Jul 29, 2024
896c1ce
Merge branch 'refs/heads/progress-tracking' into dev
Batorian Jul 29, 2024
98cd3cf
Merge branch 'refs/heads/prod' into dev
Batorian Aug 14, 2024
a7cb8a5
Merge branch 'refs/heads/prod' into sanitizer
Batorian Aug 14, 2024
1612b52
sanitizer: update sanitizer
Batorian Aug 14, 2024
ca455e1
Merge branch 'refs/heads/sanitizer' into dev
Batorian Aug 14, 2024
c062c2c
Merge branch 'LNReader:master' into dev
Batorian Aug 17, 2024
2ef4d7a
Merge branch 'LNReader:master' into sanitizer
Batorian Aug 17, 2024
3b1a9a5
Merge branch 'LNReader:master' into dev
Batorian Aug 25, 2024
e790fb2
Merge branch 'LNReader:master' into sanitizer
Batorian Aug 25, 2024
cb00c8f
sanitizer: block text-align
Batorian Aug 25, 2024
d6656da
Merge branch 'refs/heads/sanitizer' into dev
Batorian Aug 25, 2024
f15a174
Merge branch 'LNReader:master' into dev
Batorian Aug 29, 2024
51cbc66
Merge branch 'LNReader:master' into sanitizer
Batorian Aug 29, 2024
f63221e
Merge branch 'LNReader:master' into dev
Batorian Sep 8, 2024
8edd190
Merge branch 'LNReader:master' into sanitizer
Batorian Sep 8, 2024
43e5ea4
sanitizer: update img
Batorian Sep 12, 2024
fb229da
Merge branch 'prod' into sanitizer
Batorian Dec 1, 2024
28cfb57
Merge branch 'prod' into dev
Batorian Dec 1, 2024
5e0f6c8
sanitizer: reworked
Batorian Dec 7, 2024
0512d66
sanitizer: reworked
Batorian Dec 7, 2024
2755fcc
sanitizer: fixed lazyloaded images
Batorian Dec 8, 2024
633aed8
sanitizer: revert sanitizer
Batorian Dec 8, 2024
7986b3a
sanitizer: remove alt and title from images
Batorian Dec 8, 2024
c84a20f
Merge branch 'dev' into sanitizer
Batorian Dec 9, 2024
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
79 changes: 70 additions & 9 deletions src/screens/reader/utils/sanitizeChapterText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,87 @@ import { getString } from '@strings/translations';
import sanitizeHtml from 'sanitize-html';

export const sanitizeChapterText = (html: string): string => {
// List of disallowed CSS properties
const disallowedCSSProperties: RegExp[] = [
/^color$/,
/^font.*$/,
/^line-height$/,
/^max.*$/,
/^min.*$/,
/^text-indent$/,
];

// Create a transform function for the specified tags
const createTransformFunction = () => {
return (tagName: string, attribs: any) => {
if (attribs.style) {
const styles = attribs.style.split(';');
const allowedStyles = styles.filter((style: string) => {
const [property] = style.split(':');
return !disallowedCSSProperties.some(regex =>
regex.test(property.trim()),
);
});
return {
tagName: tagName,
attribs: {
...attribs,
style: allowedStyles.join(';'),
},
};
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { _style, ...rest } = attribs;
return {
tagName: tagName,
attribs: rest,
};
};
};

// List of styled tags
const styledTags = sanitizeHtml.defaults.allowedTags.concat([
'div',
'p',
'span',
]);

// Generate the transformTags object
const transformTags: {
[key: string]: (tagName: string, attribs: any) => any;
} = {};
styledTags.forEach(tag => {
transformTags[tag] = createTransformFunction();
});

let text = sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are extending the default tags. Most of the tags are already included (i think everything except img), so they are not neccessary.

'img',
'i',
'em',
'b',
'a',
'b',
'div',
'ol',
'em',
'i',
'img',
'li',
'ol',
'p',
's',
'span',
'strong',
'title',
'u',
'ul',
]),
allowedAttributes: {
'img': ['src', 'class', 'id'],
'a': ['href', 'class', 'id'],
'div': ['class', 'id'],
'p': ['class', 'id'],
'ol': ['reversed', 'start', 'type'],
'div': ['class', 'id', 'style'],
'img': ['src', 'class', 'id'],
'ol': ['reversed', 'start'],
'p': ['class', 'id', 'style'],
'span': ['class', 'id', 'style'],
},
allowedSchemes: ['data', 'http', 'https', 'file'],
transformTags: transformTags,
});
return text || getString('readerScreen.emptyChapterMessage');
};
Loading