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

remove empty whitespace-only blocks from posts #1524

Closed
wants to merge 2 commits into from

Conversation

1jz
Copy link
Contributor

@1jz 1jz commented Dec 11, 2020

Issue This PR Addresses

Fixes #1189

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Removes redundant elements wrapping <br> elements and replaces repetitive <br> elements with a single <br>

Also removes empty <p> elements.

@@ -0,0 +1,5 @@
const redundantBreaklineRegex = /(<br>((\s?)+)){2,}|((<p>|<div>)(\s+)?(<br>)(\s+)?(<\/p>|<\/div>)((\s?)+)){1,}/g;
Copy link
Contributor

Choose a reason for hiding this comment

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

Regex to deal with the DOM makes me nervous. Can you not use CSS Selectors for this? The DOM already has a parsing engine built into it without us inventing a new one via regex.

There's a famous StackOverflow answer about the perils of this: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?answertab=active#tab-top

Copy link
Contributor

@Metropass Metropass left a comment

Choose a reason for hiding this comment

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

I know this might be a bit pedantic, but I think we should also check for the 0-dot braille for security reasons. Someone could possibly embed something malicious, and use the character as a means to bypass this check. I'll make a mock function for it

@humphd humphd modified the milestones: 1.6 Release, 1.7 Release Feb 5, 2021
@huyxgit huyxgit closed this Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove empty whitespace-only blocks from posts
5 participants