Forum Replies Created

Viewing 1 replies (of 1 total)
  • After updating to 2.2.3, my site experienced the same issue:
    An inline JavaScript stopped working because backslashes have been removed.

    Comparing version 2.2.2 and 2.2.3 showed that it happens in
    "/src/class-ss-url-extractor.php"
    where in two functions a new stripslashes() has been inserted in 2.2.3

    function extract_and_replace_urls_in_html()
        $html_string = $this->get_body();
        $html_string = stripslashes( $html_string ); // 2.2.3
    
    function extract_and_replace_urls_in_script( $text )
        $text = stripslashes( $text );    // 2.2.3

    Because parameters $html_string and $text contained following (truncated) JS code, in the generated static pages, this JS code failed.

    ... "<span class=\"ast-icon icon-close\" ><\/span >" ...

    By removing these stripslashes()calls, Simply Static 2.2.3 again worked fine as version 2.2.2.

    But what about replacing URLs with rare/unusual encoding (in JS/CSS) ?
    Can we avoid stripslashes()calls and still replace all kind of encoded URLs?

    One possibility would be, by using arrays containing all (most) possible encoded URL pairs for the replacement:

    // prepare encoded URL pairs for replacement:
    $dyn[0..n]  = DYNAMIC_URLs; // encoded source URLs
    $stat[0..n] = STATIC_URLs;  // corresponding replacements
    
    str_replace( $string, $dyn, $stat );

    It would also help to provide extra filters, that allow replacing special cases of encoded URLs by using the provided URL strings to perform its own str_replace() to cover special cases.
    For example:

    apply_filters( 'ss_fix_urls', $text, $url_dyn, $url_static) 

    Last not least:
    Thank you for providing Simply Static, it works great!
    /GeHo

Viewing 1 replies (of 1 total)