You are not logged in.

#1 2022-01-10 14:44:52

flyinghelix
Member
Registered: 2022-01-10
Posts: 6

PHP Regex not Recognizing ü in PHPUnit, Arch Specific

Hello,

I am using PHP 8.0.14, tried it with php74 und php81, Xdebug 3.1.2, pcre 8.45, and both preg_match and filter_var_array do not work with this regex:

'/^(?=.*[\p{L}\p{Mn}])(?=.*[\d\W])[_\p{L}\p{Mn}\d\W]{8,128}$/'

Putting in 'gültigesPasswort12!' does not recognize for me. On windows, Ubuntu and the alpine docker image it all works fine, just not on arch. I could not find anything except maybe that pcre does not have utf-8 support, but it has for me. The php.ini also look the same on these systems. With some trying it seems the ü is the problematic character, but i want that to be recognized, as this regex is for german passwords. Is there maybe something in my locale i have to change? But i am wondering how a different systembase could affect a php regex anyways.

Last edited by flyinghelix (2022-01-11 08:39:34)

Offline

#2 2022-01-10 14:53:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 26,729
Website

Re: PHP Regex not Recognizing ü in PHPUnit, Arch Specific

flyinghelix wrote:

Is there maybe something in my locale i have to change?

Most likely yes.  How is your locale configured on each of the (linux) systems?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-01-10 15:25:12

flyinghelix
Member
Registered: 2022-01-10
Posts: 6

Re: PHP Regex not Recognizing ü in PHPUnit, Arch Specific

oh, ok, didnt think the locale would actually affect php, so it was just a guess.
on my arch distro running locale shows

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

and on PopOS (does gnome not set its locale itself?), i set it in the settings to Language English us, and german formats, as thats what i am used to, running locale produces

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

on alpine i just use the php:alpine image, not changing anything with the locale (does it even have one?)

after setting the locale in Arch to exactly the same, the problem still persists.
But i forgot to mention, that i use PHPUnit 9.5.11, and it happens when running a test, where it is included. also, if that might be the factor, i use zsh, but i just tried it with bash, no difference.

Last edited by flyinghelix (2022-01-10 15:40:36)

Offline

#4 2022-01-10 16:15:23

flyinghelix
Member
Registered: 2022-01-10
Posts: 6

Re: PHP Regex not Recognizing ü in PHPUnit, Arch Specific

turns out the regex was missing the u modifier at the end. But then i don't understand how it worked on the other systems...

Offline

#5 2022-01-11 08:47:44

flyinghelix
Member
Registered: 2022-01-10
Posts: 6

Re: PHP Regex not Recognizing ü in PHPUnit, Arch Specific

turns out, without the u modifier, it does not work within PHPunit execution, but in normal php Execution. I am not sure if this is a general bug in PHPUnit or if it is a local system Issue, that's why marked this thread as not solved anymore. If anyone using php and phpunit can test it on their system, that would be great.
the code is

<?php
class OutputTest{
  public function testOutput() {
    var_dump(preg_match('/^[\p{L}\p{Mn}\W]{8,128}$/', 'gülitgesWort'));
    var_dump(preg_match('/^[\p{L}\p{Mn}\W]{8,128}$/u', 'gülitgesWort'));
  }
}

$a = new OutputTest();
$a->testOutput();
?>

vs

<?php

use PHPUnit\Framework\TestCase;

class OutputTest extends TestCase{
  public function testOutput() {
    var_dump(preg_match('/^[\p{L}\p{Mn}\W]{8,128}$/', 'gülitgesWort'));
    var_dump(preg_match('/^[\p{L}\p{Mn}\W]{8,128}$/u', 'gülitgesWort'));
  }
}
?>

and running it with phpunit.
when running "php code1" it produces int(1) int(1), while "phpunit code2" produces int(0) int(1) for me, but only on Arch.

Offline

Board footer

Powered by FluxBB