Pattern attribute sanitization may break regex

Support General Pattern attribute sanitization may break regexResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #43742
    JackkyJackky
    Participant

    It's seems, MetaBox sanitizing each attribute of field, including pattern input attribute.
    Since I was trying to use complex regex with it, I got non-working result because of sanitization.
    Code:
    `
    'pattern' => '(?:https?:)?(?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])(?:[\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*>|<\/a>))[?=&+%\w.-]*',
    `
    Rendered result (HTML):
    `
    <input pattern="(?:https?:)?(?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])(?:[\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*">
    `

    #43745
    JackkyJackky
    Participant

    Ok, forum collapse entities also they are inside backticks... Here a pastebin, where converted entities are shown.

    #43747
    PeterPeter
    Moderator

    Hello Jackky,

    Do you mean some HTML entities are converted to single characters? For example: &amp ; - &
    Then the sanitization does not work as expected.

    #43953
    JackkyJackky
    Participant

    Yes, but regex must render "as is" inside the pattern attribute

    #43955
    PeterPeter
    Moderator

    Hello,

    I've escalated this issue to the development team to fix this in future updates. Thank you.

    #46538
    Anh TranAnh Tran
    Keymaster

    Hi Jackky,

    After checking this issue, I found that it's probably the browser issue. The pattern regex is outputted correctly in the input, but the browser displays it as rendered entities.

    When you view the source code of the page, you'll see the pattern attribute is outputted correctly. But when you *inspect* the input with the browser inspector, it will shows rendered entities. So, it seems to be an issue with viewing in the browser instead of a technical issue, which probably can't be fixed.

    I created a demo with pure HTML for you to check here.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.