ExpressionEngine / ExpressionEngine

ExpressionEngine is a flexible, feature-rich, free open-source content management platform that empowers hundreds of thousands of individuals and organizations around the world to easily manage their web site.
https://expressionengine.com
Other
455 stars 124 forks source link

url_title generated by ee('Format') urlSlug method fails validation (EE7.4.5) #4246

Closed jcogs-design closed 5 months ago

jcogs-design commented 5 months ago

Description of the problem Am auto-generating url_title elements for channel entries in an add-on. Using the following to generate the url_title element


$url_title = substr(ee('Format')->make('Text', $data_item)->urlSlug(['remove_stopwords' => TRUE])->compile(),0,199);
This generates url_title elements such as `acrandjute30m-acoustix-jute-randstrook-30-lm*5mm*100mm-uitlopend` from a source string of `ACRANDJUTE30M-Acoustix jute randstrook 30 lm*5mm*100mm uitlopend`. Unfortunately this url_title fails to validate - this is the result of validating a new channel entry using this url_title

object(ExpressionEngine\Service\Validation\Result)[2675]
  protected 'default_view' => null
  protected 'line_view' => null
  protected 'failed' => 
    array (size=1)
      'url_title' => 
        array (size=1)
          0 => 
            object(ExpressionEngine\Service\Validation\Rule\AlphaDashPeriodEmoji)[36495]
              ...
This appears to be a bug. **How To Reproduce** Hopefully the above explanation is clear enough. **Environment Details:** - Version: 7.4.5 - PHP Version 8.1.13 - MySQL Version MariaDb 10.4.27 - Web Server: nginx
jcogs-design commented 5 months ago

It appears that the rogue character being left in the url_title is the asterisk. The following code applied after the urlSlug call seems to fix the issue...


// Clean up url_title
$stop_characters = ['*'];
$url_title = str_replace($stop_characters, '_', $url_title);