Skip to content

Commit

Permalink
Fix 1638 by disallowing [ as part of the property name
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jun 7, 2016
1 parent 0ffc3b0 commit 341fd42
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
"smw-pa-property-predefined_errp": "\"$1\" is a predefined property to track input errors for irregular value annotations that was likely caused by type or [[Property:Allows value|allowed value]] restrictions and is provided by [https://www.semantic-mediawiki.org/wiki/Help:Special_properties Semantic MediaWiki].",
"smw-pa-property-predefined_pval": "[https://www.semantic-mediawiki.org/wiki/Help:Special_property_Allows_value \"$1\"] is a predefined property that can define a list of permissible values to restrict value assignments for a property and is provided by [https://www.semantic-mediawiki.org/wiki/Help:Special_properties Semantic MediaWiki].",
"smw-datavalue-property-restricted-use": "Property \"$1\" has been marked for restricted use.",
"smw-datavalue-property-invalid-name": "Property name contains invalid characters (e.g. $1) .",
"smw-datavalue-property-invalid-name": "The value \"$1\" contains invalid characters (e.g. $2) for a property name.",
"smw-datavalue-restricted-use": "Datavalue \"$1\" has been marked for restricted use.",
"smw-datavalue-invalid-number": "\"$1\" can not be interpreted as a number.",
"smw-query-condition-circular": "A possible circular condition has been detected in \"$1\".",
Expand Down
7 changes: 4 additions & 3 deletions includes/datavalues/SMW_DV_Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,10 @@ public function getText() {

private function doNormalizeUserValue( $value ) {

// #1567
if ( strpos( $value, '#' ) !== false && strlen( $value ) > 1 ) {
$this->addErrorMsg( array( 'smw-datavalue-property-invalid-name', '#' ) );
if (
( $pos = strpos( $value, '#' ) ) !== false && strlen( $value ) > 1 || /* #1567 */
( $pos = strpos( $value, '[' ) ) !== false ) /* #1638 */ {
$this->addErrorMsg( array( 'smw-datavalue-property-invalid-name', $value, substr( $value, $pos, 1 ) ) );
$this->m_dataitem = new DIProperty( 'ERROR', false );
}

Expand Down
1 change: 1 addition & 0 deletions includes/querypages/PropertiesQueryPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ private function getUserDefinedPropertyInfo( $title, $property, $useCount ) {
private function getPredefinedPropertyInfo( DIProperty $property ) {

$dv = DataValueFactory::getInstance()->newDataItemValue( $property, null );
$dv->setCaption( $property->getLabel() );

$dv->setLinkAttributes( array(
'title' => 'ID: ' . ( isset( $property->id ) ? $property->id : 'N/A' ) . ' (' . $property->getKey() . ')'
Expand Down
17 changes: 16 additions & 1 deletion tests/phpunit/Integration/ByJsonScript/Fixtures/p-0102.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Test in-text annotation on properties with invalid names/charaters (#1567, `wgContLang=en`)",
"description": "Test in-text annotation on properties with invalid names/charaters (#1567, #1638, `wgContLang=en`)",
"properties": [
{
"name": "Has #",
Expand All @@ -19,6 +19,10 @@
"name": "Example/P0102/3",
"contents": "[[<code>Has property e::ABC]] {{#set: <code>Has property f=DEF }}"
},
{
"name": "Example/P0102/4",
"contents": "[[File:[[Picture:: Foo.png ]]"
},
{
"name": "Example/P0102/Q3.1",
"contents": "{{#ask: [[<code>Has property e::ABC]] |link=none |format=table |sort=# |order=asc}}"
Expand Down Expand Up @@ -70,6 +74,17 @@
"propertyKeys": [ "_ASK", "_MDAT", "_SKEY" ]
}
}
},
{
"about": "#4 `[` to produce an error",
"subject": "Example/P0102/4",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 3,
"propertyKeys": [ "_ERRC", "_MDAT", "_SKEY" ]
}
}
}
],
"settings": {
Expand Down

0 comments on commit 341fd42

Please sign in to comment.