processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

Sanitizer PageNameTranslate returns empty result with dots #1948

Closed FlipZoomMedia closed 4 days ago

FlipZoomMedia commented 1 week ago

There is a problem with the sanitizer methods:

$sanitizer->pageNameTranslate('String');
$sanitizer->pageName('String', Sanitizer::translate);

insofar as the dot is configured in the "InputfieldPageName" module so that the dot is not allowed (the dot is replaced by nothing; this is necessary for specific bug with the ProCache buster method C and path versioning).

image

This means that if the string contains a dot, nothing is returned. It should actually be the case that the dot is simply removed and the rest of the string is returned.

image

Setup/Environment

ryancramerdesign commented 1 week ago

@FlipZoomMedia I can't seem to duplicate here yet. Can you spot anything I'm missing? I updated my InputfieldPageName module config to set .= in the character replacements. Then I used this code to test:

$a = [
  'without dot: ' => 'demo åöü without dot',
  'with dot: ' => 'demo åöü with . dot',  
];
echo "<table>";
foreach($a as $k => $v) {
  echo "<tr><td>pageNameTranslate $k</td><td>" . $sanitizer->pageNameTranslate($v) . "</td></tr>";
  echo "<tr><td>pageName $k</td><td>" . $sanitizer->pageName($v, Sanitizer::translate) . "</td></tr>";
}
echo "</table>";

and here's the result I got:

Screen Shot 2024-07-05 at 10 22 11 AM
adrianbj commented 1 week ago

@ryancramerdesign - while you're in this part of the core, any chance of looking at this one: https://github.com/processwire/processwire-issues/issues/1344

and also revisiting the inconsistency issue I note in my final comment on this one: https://github.com/processwire/processwire-issues/issues/1305

FlipZoomMedia commented 1 week ago

@FlipZoomMedia I can't seem to duplicate here yet. Can you spot anything I'm missing? I updated my InputfieldPageName module config to set .= in the character replacements. Then I used this code to test:

$a = [
  'without dot: ' => 'demo åöü without dot',
  'with dot: ' => 'demo åöü with . dot',  
];
echo "<table>";
foreach($a as $k => $v) {
  echo "<tr><td>pageNameTranslate $k</td><td>" . $sanitizer->pageNameTranslate($v) . "</td></tr>";
  echo "<tr><td>pageName $k</td><td>" . $sanitizer->pageName($v, Sanitizer::translate) . "</td></tr>";
}
echo "</table>";

and here's the result I got: Screen Shot 2024-07-05 at 10 22 11 AM

Hi @ryancramerdesign,

I also get empty results with your example. 🤷‍♂️

image

If I remove .= from the config, it works without any problems. I'm not quite sure how to debug further. The installations have a lot of modules, but I don't think they have any direct influence or use hooks in that area.

screencast-stage.flipzoom.de-2024.07.05-16_49_32.webm

I list mall modules here. I'll have to try this on a fresh PW installation. Unfortunately I can't do it anymore today.

Server Details

Software Version
ProcessWire 3.0.229
PHP 8.3.8
Webserver Apache
MySQL Server 10.3.39-MariaDB
MySQL Client mysqlnd 8.3.8
Server Settings |Parameter|Value| |------:|:-------| |allow_url_fopen|1| |max_execution_time|90 (changeable)| |max_input_nesting_level|64| |max_input_time|90| |max_input_vars|1000| |memory_limit|128M| |post_max_size|32M| |upload_max_filesize|32M| |xdebug|| |xdebug.max_nesting_level|| |mod_rewrite|1| |mod_security|| |EXIF Support|1| |FreeType|1|
GD Settings |Parameter|Value| |------:|:-------| |Version|bundled (2.1.0 compatible)| |GIF|1| |JPG|1| |PNG|1| |WebP|1| |AVIF||
iMagick Settings |Parameter|Value| |------:|:-------| |Version|6.9.13| |GIF|1| |JPG|1| |PNG|1| |SVG|1| |PDF|1| |WebP|1| |AVIF||
Module Details |Module ClassName|Version| |------:|:-------| |AdminThemeBoss|0.6.3| |AdminThemeGrow|1.0.0| |FieldtypeColor|1.2.1| |FieldtypeCombo|0.1.5| |FieldtypeFieldsetGroup|0.0.4| |FieldtypeFunctional|0.0.3| |FieldtypeMultiplier|0.1.5| |FieldtypeMystique|0.0.21| |FieldtypePageHitCounter|1.2.3| |FieldtypeRangeSlider|1.0.4| |FieldtypeRepeaterMatrix|0.1.1| |FieldtypeTable|0.3.0| |FieldtypeTextUnique|3.0.1| |FieldtypeTextareas|0.1.0| |FieldtypeURLLanguage|0.0.2| |FileValidatorSvgSanitizer|0.0.5| |FormBuilder|0.5.5| |HannaCodeDialog|0.4.4| |ImageCropRatios|0.1.2| |InputfieldChosenSelect|1.2.5| |InputfieldChosenSelectMultiple|1.2.0| |InputfieldColor|1.1.7| |InputfieldCombo|0.1.5| |InputfieldFormBuilderFile|0.0.3| |InputfieldFunctional|0.0.3| |InputfieldMultiplier|0.1.5| |InputfieldMystique|0.0.21| |InputfieldRangeSlider|1.0.4| |InputfieldRepeaterMatrix|0.1.1| |InputfieldRepeaterMatrixDuplicate|2.0.2| |InputfieldTable|0.3.0| |InputfieldTextareas|0.1.0| |Less|0.0.5| |MarkupMenuBuilder|0.2.7| |MarkupRSSFeed|1.0.5| |MarkupSEOCustom|0.9.1| |MarkupSitemapCustom|0.3.4| |Mystique|0.0.21| |PageHitCounter|2.0.0| |PageListSelectMultipleQuickly|0.1.2| |PagePublisher|1.1.0| |PageUnpublishedPreview|1.0.0| |ProCache|4.0.5| |Process404PageLogger|1.0.0| |ProcessDatabaseBackups|0.0.6| |ProcessFormBuilder|0.5.5| |ProcessHannaCode|0.3.2| |ProcessLanguageFieldExportImport|0.1.0| |ProcessMenuBuilder|0.2.7| |ProcessPageListMultipleSorting|1.0.1| |ProcessPredefinedImageSizes|1.0.6| |ProcessProCache|4.0.5| |ProcessRedirectsCustom|1.0.5| |ProcessTracyAdminer|2.0.1| |ProcessTracyAdminerRenderer|2.0.2| |ProcessTranslationManager|1.0.1| |ProcessWireUpgrade|0.1.1| |ProcessWireUpgradeCheck|0.0.9| |RockFinder3|1.0.21| |RockFinder3Master|1.0.7| |TextformatterAutoHyphen|1.0.0| |TextformatterBuster|0.0.1| |TextformatterHannaCode|0.3.2| |TextformatterVideoOrSocialPostEmbedCustom|1.2.3| |TracyDebugger|4.26.27| |WireMailSmtp|0.6.4|
ryancramerdesign commented 1 week ago

@FlipZoomMedia Do you have $config->pageNameCharset set to something in your /site/config.php file? (default is ascii). If you have it set to UTF8 then check if you are also overriding the $config->pageNameWhitelist value?

Do you have the LanguageSupport modules installed or not installed?

FlipZoomMedia commented 1 week ago

Hi @ryancramerdesign, I just tested it again with a completely fresh installation. Only TracyDebugger is installed, otherwise PW Main 3.0.229 and the Blank Profile. Same problem:

image

FlipZoomMedia commented 1 week ago

@FlipZoomMedia Do you have $config->pageNameCharset set to something in your /site/config.php file? (default is ascii). If you have it set to UTF8 then check if you are also overriding the $config->pageNameWhitelist value?

Do you have the LanguageSupport modules installed or not installed?

No, none of the configurations mentioned. All default. In one installation the LanguageSupport modules are installed, in the fresh installation they are not.

ryancramerdesign commented 1 week ago

@FlipZoomMedia Just found out that I made a mistake. Too many windows open and it looks like I added .= to a different installation than the one I was testing. Sorry about that. I'm going to re-try here.

ryancramerdesign commented 1 week ago

@FlipZoomMedia I was able to duplicate it after correcting my mistake. I've refactored that part of the code a bit, which seems to fix it. Thanks.

FlipZoomMedia commented 4 days ago

Thank you, the fix works.