Skip to content

Commit

Permalink
Improved language ID validation
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Apr 12, 2017
1 parent 5cebd05 commit 657c47a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
11 changes: 9 additions & 2 deletions lib/mshoplib/src/MShop/Common/Item/Base.php
Expand Up @@ -307,11 +307,18 @@ protected function checkLanguageId( $langid, $null = true )

if( $langid != null )
{
if( preg_match( '/^[a-z]{2}(_[A-Z]{2})?$/', $langid ) !== 1 ) {
if( preg_match( '/^[a-zA-Z]{2}(_[a-zA-Z]{2})?$/', $langid ) !== 1 ) {
throw new \Aimeos\MShop\Exception( sprintf( 'Invalid ISO language code "%1$s"', $langid ) );
}

return $langid;
$parts = explode( '_', $langid );
$parts[0] = strtolower( $parts[0] );

if( isset( $parts[1] ) ) {
$parts[1] = strtoupper( $parts[1] );
}

return implode( '_', $parts );
}
}

Expand Down
7 changes: 0 additions & 7 deletions lib/mshoplib/tests/MShop/Locale/Item/StandardTest.php
Expand Up @@ -141,13 +141,6 @@ public function testSetLanguageIdCountryInvalid()
}


public function testSetLanguageIdCountryInvalidLowerCase()
{
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
$this->object->setLanguageId( 'en_gb' );
}


public function testGetCurrencyId()
{
$this->assertEquals( 'EUR', $this->object->getCurrencyId() );
Expand Down
2 changes: 1 addition & 1 deletion lib/mshoplib/tests/MShop/Media/Item/StandardTest.php
Expand Up @@ -145,7 +145,7 @@ public function testSetLanguageId()
public function testSetLanguageIdInvalid()
{
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
$this->object->setLanguageId( 'EN' );
$this->object->setLanguageId( '00' );
}


Expand Down

0 comments on commit 657c47a

Please sign in to comment.