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

Vertical Alignment not removed #391

Closed
noudadrichem opened this issue Jul 29, 2020 · 4 comments
Closed

Vertical Alignment not removed #391

noudadrichem opened this issue Jul 29, 2020 · 4 comments

Comments

@noudadrichem
Copy link

PLEASE NOTE: make sure the bug exists in the latest patch level of the project. For instance, if you are running a 2.x version of Apostrophe, you should use the latest in that major version to confirm the bug.

To Reproduce

Step by step instructions to reproduce the behavior:

  1. Go to 'html'
  2. Click on 'terminal'
  3. Scroll down to 'where it started'
  4. See error

Expected behavior

My expected output is:
<font><font>SHOP NOW</font></font>
But got:
<font style="vertical-align:inherit"><font style="vertical-align:inherit">SHOP NOW</font></font>

Describe the bug

sanitizeHtml is not removing vertical-align from the HTML

Details

Version of Node.js:
PLEASE NOTE: Only stable LTS versions (10.x and 12.x) are fully supported but we will do our best with newer versions.
~/code/testing-sanitize » node -v
v10.8.0

Server Operating System:
MacOS Version 10.15.4

Additional context:
I created this code snippet to extract the problem from the bigger service.

const sanitizeHtml = require('sanitize-html');
const HTML = `<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">SHOP NOW</font></font>`

function testVerticalAlignRemovement(html) {
    const clean = sanitizeHtml(html, {
        allowedTags: ['div', 'br', 'font', 'span', 'b', 'strong', 'i', 'u', '<strike>'],
        allowedAttributes: {
            'font': ['color', 'face', 'size', 'style'],
            'span': ['style']
        },
        allowedStyles: {
            'color': ['*'],
            'font-weight': ['*'],
            'font-style': ['*'],
            'text-transform': ['*'],
            'text-decoration': ['*'],
            'text-shadow': ['*']
        }
    });
    console.log(clean);
}

testVerticalAlignRemovement(HTML);

// expected output => <font"><font>SHOP NOW</font></font>

// got output => <font style="vertical-align:inherit"><font style="vertical-align:inherit">SHOP NOW</font></font>

Aka it didn't do anything..

Screenshots
Terminal issue:

<font style="vertical-align:inherit"><font style="vertical-align:inherit">SHOP NOW</font></font>```

@noudadrichem noudadrichem added the bug Something isn't working label Jul 29, 2020
@abea
Copy link
Contributor

abea commented Jul 29, 2020

Please review the allowedStyles docs again. You need to include the element name (or '*' for the set of styles you're allowing. https://github.com/apostrophecms/sanitize-html#allowed-css-styles

@abea abea closed this as completed Jul 29, 2020
@boutell
Copy link
Member

boutell commented Jul 29, 2020 via email

@noudadrichem
Copy link
Author

I want vertical-alignment to be gone in the style attribute on font. So it not being there in 'allowedStyles' should remove it. That's how I read the docs as well. (see expected output)

@noudadrichem
Copy link
Author

noudadrichem commented Jul 29, 2020

I got it working by adding this:

        allowedStyles: {
            '*': {
                'color': ['*'],
                'font-weight': ['*'],
                'font-style': ['*'],
                'text-transform': ['*'],
                'text-decoration': ['*'],
                'text-shadow': ['*'],
            }
        }

@abea abea removed the bug Something isn't working label Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants