Bug: Blog image breaks formatting when it ends at a certain place

Created on 14 September 2023, over 1 year ago

Problem/Motivation

This error was reported by Vermont Housing Finance Agency.

"The blog image breaks formatting when the first paragraph breaks on a certain line. This is fixed on the live site, but you can see in the screenshot what happens, image is centered and a random p> follows. Fixed for now by breaking the paragraph after the first sentence (or I could have combined the first two paragraphs). Could you fix this?"

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mlncn
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Problem identified: The text here:

    the β€œ10% in Vermont” local investment program.

    has multibyte characters for the fancy quotation marks, and that throws off substr_replace which is not multibyte safe.

  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Surprisingly little discussion about dealing with this. There's https://github.com/wpsharks/comet-cache/issues/703 and,

    from https://sourceforge.net/p/wikindx/svn/HEAD/tree/trunk/core/libs/UTF8.php comes one replacement function:

        /**
         * Simulate substr_replace() for multibytes strings
         *
         * @param string $string
         * @param string $replacement
         * @param int $start
         * @param int $length Default is NULL.
         * @param string $encoding Default is NULL.
         *
         * @return string
         */
        function mb_substr_replace($string, $replacement, $start, $length = NULL, $encoding = NULL)
        {
            $string_length = (is_null($encoding) === TRUE) ? mb_strlen($string) : mb_strlen($string, $encoding);
    
            if ($start < 0)
            {
                $start = max(0, $string_length + $start);
            }
            elseif ($start > $string_length)
            {
                $start = $string_length;
            }
    
            if ($length < 0)
            {
                $length = max(0, $string_length - $start + $length);
            }
            elseif ((is_null($length) === TRUE) || ($length > $string_length))
            {
                $length = $string_length;
            }
    
            if (($start + $length) > $string_length)
            {
                $length = $string_length - $start;
            }
    
            if (is_null($encoding) === TRUE)
            {
                return mb_substr($string, 0, $start) . $replacement . mb_substr($string, $start + $length, $string_length - $start - $length);
            }
    
            return mb_substr($string, 0, $start, $encoding) . $replacement . mb_substr($string, $start + $length, $string_length - $start - $length, $encoding);
        }
    

    But it turns out we could use an even more simple version of a simple version suggested in the PHP manual for substr_replace here https://www.php.net/manual/en/function.substr-replace.php#48066

    • mlncn β†’ committed fec52292 on 1.0.x
      Issue #3387419: Bug: Blog image breaks formatting when it ends at a...
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA
Production build 0.71.5 2024