Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/298109
Change subject: Fix writing string with bad language tag.
......................................................................
Fix writing string with bad language tag.
Bug: T139687
Change-Id: I131ffae137a05096540f6a29f8124bd3f5a65d52
---
M src/N3RdfWriterBase.php
M tests/data/Texts.nt
M tests/data/Texts.ttl
M tests/phpunit/RdfWriterTestBase.php
4 files changed, 11 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/09/298109/1
diff --git a/src/N3RdfWriterBase.php b/src/N3RdfWriterBase.php
index dfbe861..7d64aff 100644
--- a/src/N3RdfWriterBase.php
+++ b/src/N3RdfWriterBase.php
@@ -52,7 +52,8 @@
$value = $this->quoter->escapeLiteral( $text );
$this->write( '"' . $value . '"' );
- if ( $language !== null ) {
+ // preg_match is somewhat (12%) slower than strspn but more
readable
+ if ( $language !== null && preg_match( '/^[0-9A-Za-z-]+$/',
$language ) ) {
$this->write( '@' . $language );
}
}
diff --git a/tests/data/Texts.nt b/tests/data/Texts.nt
index d927334..bf26a0e 100644
--- a/tests/data/Texts.nt
+++ b/tests/data/Texts.nt
@@ -1,2 +1,4 @@
<http://acme.test/Bongos> <http://acme.test/sounds> "Bom"@de .
<http://acme.test/Bongos> <http://acme.test/sounds> "Bam"@en .
+<http://acme.test/Bongos> <http://acme.test/sounds> "Como estas"@es-419 .
+<http://acme.test/Bongos> <http://acme.test/sounds> "What?" .
diff --git a/tests/data/Texts.ttl b/tests/data/Texts.ttl
index ccb4c2a..a602818 100644
--- a/tests/data/Texts.ttl
+++ b/tests/data/Texts.ttl
@@ -3,4 +3,6 @@
@prefix acme: <http://acme.test/> .
acme:Bongos acme:sounds "Bom"@de,
- "Bam"@en .
+ "Bam"@en,
+ "Como estas"@es-419,
+ "What?" .
diff --git a/tests/phpunit/RdfWriterTestBase.php
b/tests/phpunit/RdfWriterTestBase.php
index 72d339d..965572b 100644
--- a/tests/phpunit/RdfWriterTestBase.php
+++ b/tests/phpunit/RdfWriterTestBase.php
@@ -217,7 +217,10 @@
$writer->about( 'acme', 'Bongos' )
->say( 'acme', 'sounds' )
->text( 'Bom', 'de' )
- ->text( 'Bam', 'en' );
+ ->text( 'Bam', 'en' )
+ ->text( 'Como estas', 'es-419' )
+ ->text( 'What?', 'bad tag' )
+ ;
$writer->finish();
$rdf = $writer->drain();
--
To view, visit https://gerrit.wikimedia.org/r/298109
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I131ffae137a05096540f6a29f8124bd3f5a65d52
Gerrit-PatchSet: 1
Gerrit-Project: purtle
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits