Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InTextAnnotationParser to check for possible pipe split, refs #1747 #1753

Merged
merged 1 commit into from Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/InTextAnnotationParser.php
Expand Up @@ -205,6 +205,12 @@ function( array $matches ) {
}

if ( array_key_exists( 2, $matches ) ) {

// #1747
if ( strpos( $matches[1], '|' ) !== false ) {
return $matches[0];
}

$parts = explode( '|', $matches[2] );
$value = array_key_exists( 0, $parts ) ? $parts[0] : '';
$caption = array_key_exists( 1, $parts ) ? $parts[1] : false;
Expand Down Expand Up @@ -307,7 +313,16 @@ protected function preprocess( array $semanticLink ) {
$caption = false;

if ( array_key_exists( 2, $semanticLink ) ) {

// #1747 avoid a mismatch on an annotation like [[Foo|Bar::Foobar]]
// where the left part of :: is split and would contain "Foo|Bar"
// hence this type is categorized as no value annotation
if ( strpos( $semanticLink[1], '|' ) !== false ) {
return $semanticLink[0];
}

$parts = explode( '|', $semanticLink[2] );

if ( array_key_exists( 0, $parts ) ) {
$value = $parts[0];
}
Expand Down
68 changes: 68 additions & 0 deletions tests/phpunit/Integration/ByJsonScript/Fixtures/p-0433.json
@@ -0,0 +1,68 @@
{
"description": "Test in-text annotation `::` with left pipe (#1747, `wgContLang=en`)",
"properties": [
{
"name": "Has text",
"contents": "[[Has type::Text]]"
}
],
"subjects": [
{
"name": "Example/P0433/1",
"contents": "[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]"
},
{
"name": "Example/P0433/2",
"contents": "{{#set:Has text=[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]] }}"
},
{
"name": "Example/P0433/Q.1",
"contents": "{{#ask: [[Example/P0433/2]] |?Has text |link=none}}"
}
],
"parser-testcases": [
{
"about": "#0 no annotation due to left pipe",
"subject": "Example/P0433/1",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 3,
"propertyKeys": [ "_SKEY", "_MDAT", "_INST" ],
"propertyValues": []
}
}
},
{
"about": "#1",
"subject": "Example/P0433/2",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 3,
"propertyKeys": [ "_SKEY", "_MDAT", "Has_text" ],
"propertyValues": [ "[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]" ]
}
}
},
{
"about": "#2",
"subject": "Example/P0433/Q.1",
"expected-output": {
"to-contain": [
"title=\"File:Example.png\">Caption</a>",
"title=\"File:Example.png\">Bar::Foobar</a>"
]
}
}
],
"settings": {
"wgContLang": "en",
"smwgPageSpecialProperties": [ "_MDAT" ]
},
"meta": {
"version": "0.1",
"is-incomplete": false,
"debug": false
}
}
45 changes: 43 additions & 2 deletions tests/phpunit/Unit/InTextAnnotationParserTest.php
Expand Up @@ -259,7 +259,7 @@ public function testProcessOnReflection() {
}

/**
* @dataProvider textWithAnnotationProvider
* @dataProvider stripTextWithAnnotationProvider
*/
public function testStrip( $text, $expectedRemoval, $expectedObscuration ) {

Expand All @@ -274,7 +274,7 @@ public function testStrip( $text, $expectedRemoval, $expectedObscuration ) {
);
}

public function textWithAnnotationProvider() {
public function stripTextWithAnnotationProvider() {

$provider = array();

Expand Down Expand Up @@ -314,6 +314,13 @@ public function textWithAnnotationProvider() {
'Suspendisse tincidunt semper facilisi'
);

// #1747
$provider[] = array(
'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]',
'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]',
'&#x005B;&#x005B;Foo|Bar::Foobar]] &#x005B;&#x005B;File:Example.png|alt=Bar::Foobar|Caption]] &#x005B;&#x005B;File:Example.png|Bar::Foobar|link=Foo]]'
);

return $provider;
}

Expand Down Expand Up @@ -546,6 +553,40 @@ public function textDataProvider() {
)
);

#11 #1747 (left pipe)
$provider[] = array(
NS_MAIN,
array(
'smwgNamespacesWithSemanticLinks' => array( NS_MAIN => true ),
'smwgLinksInValues' => false,
'smwgInlineErrors' => true,
'smwgEnabledInTextAnnotationParserStrictMode' => false
),
'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]',
array(
'resultText' => '[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[File:Example.png|Bar::Foobar|link=Foo]]',
'propertyCount' => 0,
)
);

#12 #1747 (left pipe + including one annotation)
$provider[] = array(
NS_MAIN,
array(
'smwgNamespacesWithSemanticLinks' => array( NS_MAIN => true ),
'smwgLinksInValues' => false,
'smwgInlineErrors' => true,
'smwgEnabledInTextAnnotationParserStrictMode' => true
),
'[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[Foo::Foobar::テスト]] [[File:Example.png|Bar::Foobar|link=Foo]]',
array(
'resultText' => '[[Foo|Bar::Foobar]] [[File:Example.png|alt=Bar::Foobar|Caption]] [[:Foobar::テスト|Foobar::テスト]] [[File:Example.png|Bar::Foobar|link=Foo]]',
'propertyCount' => 1,
'propertyLabels' => array( 'Foo' ),
'propertyValues' => array( 'Foobar::テスト' )
)
);

return $provider;
}

Expand Down