Html Minifier breaks when user input contains ‘<' symbol

  Kiến thức lập trình

We have a system in place where users can type a custom message and this will be send as an email to other users.

We wrap the user input into an HTML email template and minify this

htmlMinifier.minify(wrappedBody, { collapseWhitespace: true, removeTagWhitespace: true, minifyCSS: true })

The wrapped body contains the entire html email that we want to minify.

This works perfect unless in the case the user enters the ‘<‘ symbol without it being an actual html tag, then the parsing fails. If the users enters html tags it works.

For example this user wanted to put a hearth in his message ‘<3’

<div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">       
        <div style="padding: 0 20px; color: #3e3e3e; font-family: 'Montserrat', Helvetica, Arial, sans-serif; font-size: 14px;line-height: 23px;">
          <!--[if mso | IE]>
          <div style="line-height:100%">
          <![endif]-->
          <p>Dear,</p><p>You where contacted with the following message:</p><pre> custom message entered by user <3 </pre><p>With kind regards,</p>
          <!--[if mso | IE]>
          </div>
          <![endif]-->
        </div>
      </div>

The minifying of the html sample above will break because of the ‘<3’

Is there a way the minifier does not break when the user inputs the ‘<‘ symbol in the custom message without it being an actual html tag?

4

LEAVE A COMMENT