• Resolved Mizagorn

    (@mizagorn)


    Hi, I was wondering if anyone has seen this problem regarding URLs generated by the [img] shortcode.

    For example, if this image is put in like this:
    [img]https://example.com/wp-content/uploads/album/254/BW-Kal-600x600.png[/img]

    The browser (at least Firefox) returns a 404 Not Found on the URL that is generated. What’s funny is that if you look at the Page Source, it looks like this:
    <img class="d4pbbc-image" src="https://example.com/wp-content/uploads/album/254/BW-Kal-600x600.png.png">

    which is fine! But, if you go to the Network tab of Firefox’s Inspect Element window, then click on the 404 line for that image, then click on the “Edit and Resend” button, the actual URL is this:
    https://example.com/wp-content/uploads/album/254/BW-Kal-600%C3%97600.png

    Very strange! If I manually edit the HTML to replace %C3%97 with x (like it is supposed to be), then the page will load the image.

    I found code in the bbcodes.php file in lines 487-502 like this:

    public function shortcode_img($atts, $content = null) {
            if (is_null($content)) return '';
            if (!$this->_scope()) return $content;
    
            $atts = $this->_atts('img', $atts);
            $args = isset($this->shortcodes['img']['args']) ? $this->shortcodes['img']['args'] : array();
            $args['src'] = $content;
    
            if ($atts['img'] != '') {
                $parts = explode("x", $atts['img'], 2);
    
                if (count($parts) == 2) {
                    $args['width'] = intval($parts[0]);
                    $args['height'] = intval($parts[1]);
                }
            }

    So that is at least one place where it is trying to find an x so it can generate the width and height attributes.

    I can’t figure out where else the URL for the image src= is generated.

    Any ideas?

    https://www.ads-software.com/plugins/gd-bbpress-tools/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Mizagorn

    (@mizagorn)

    Chrome has the URL looking like this in its “Sources” tab:

    <img class="d4pbbc-image" src="https://nodewerk.com/wp-content/uploads/album/254/BW-Kal-600& #215;600.png" />

    Notice the & #215; (without the space so I could show it). That is the HTML escape code for “times”. In other words, the ‘x’ in the image URL meaning “by” is being replaced with ‘x’ meaning “times” (multiplication).

    So when I said “which is fine”, what I guess I meant was “it *looks* fine”. ??

    Thread Starter Mizagorn

    (@mizagorn)

    Found the solution. Neither in GD bbPress Tools or bbPress itself. This is native WordPress functionality. Thanks to the author of this plugin for a great job! Here is what I posted to the WordPress “Suggestions and Features” forum:
    ———————————————————
    Hi, I am using bbPress and GD bbPress Tools on an installation.

    With Tools, you can embed an image using a shortcode as such:
    [img]https://example.com/wp-content/uploads/album/171/BW-600×600.png[/img]

    The “x” above was being replaced by the escape code for “times” & #215; (without the space, of course).

    I thought it was Tools making the conversion, because the HTML for the reply within the admin area was correct (with the “x”).

    Deactivated Tools, still happening (although the image shortcode was no longer being called, of course).

    Then I looked through bbPress code, then wound up in the Codex. Saw a suggestion in an article about sanitizing and escaping user data to take a look at how formatting.php works, and saw this on lines 290-294:

    // 9x9 (times), but never 0x9999
    if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
    	// Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
    	$curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(\d[\d\.,]*)\b/', '$1×$2', $curl );
    }

    That section of code is changing the “x” (meaning “by”) to the symbol “×” (meaning “times”). I just commented out those lines on this particular installation and problem solved.

    Suggestion: extend preg_match or add code to see if “x” is contained within a file name in the multiplication test logic.

    Thank you!

    Thread Starter Mizagorn

    (@mizagorn)

    Marked as resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[img] shortcode embeds URL encoding?’ is closed to new replies.