Problem/Motivation

VAT module declares properties named like 'vat|de_reduced|07_1983'. The pipe is not allowed in XML elements.
This in a setup using VAT module any restws XML request that contains a price field will error due to a DomError.

Proposed resolution

Make restws ignore such properties.

Remaining tasks

Review patch, commit.

Original report

commerce_product/6977.xml raises exception:

DOMException: Invalid Character Error in DOMDocument->createElement() (line 663 of sites/all/modules/restws/restws.formats.inc). Backtrace:
DOMDocument->createElement('vat|de_reduced|07_1983') restws.formats.inc:663
RestWSFormatXML::addToXML(Object, Object, Object) restws.formats.inc:665
RestWSFormatXML::addToXML(Object, Object, Object) restws.formats.inc:494
RestWSFormatXML->viewResource(Object, '6977', '') restws.module:147
restws_handle_request('view', Object, 'commerce_product', '6977', '') restws.module:365
restws_page_callback('commerce_product') 
call_user_func_array('restws_page_callback', Array) menu.inc:519
menu_execute_active_handler() index.php:21

no wonder, the VAT module has keys like 'vat|de_reduced|07_1983' which is no valid xml element.

we can say, "VAT, you shouldn't do this", but given modules use non-machine names let's see if we can do some escaping.

see the json:

  "commerce_price": {
    "amount": "745",
    "amount_decimal": 7.45,
    "currency_code": "EUR",
    "data": {
      "components": [
        
      ]
    },
    "base_price": {
      "amount": false,
      "currency_code": false,
      "data": false
    },
    "discount": {
      "amount": false,
      "currency_code": false,
      "data": false
    },
    "fee": {
      "amount": false,
      "currency_code": false,
      "data": false
    },
    "shipping": {
      "amount": false,
      "currency_code": false,
      "data": false
    },
    "flat_rate_dhl": {
      "amount": false,
      "currency_code": false,
      "data": false
    },
    "vat|de_reduced|07_1983": {
      "amount": false,
      "currency_code": false,
      "data": false
    },
    "vat|de_standard|19_2007": {
      "amount": false,
      "currency_code": false,
      "data": false
    }
  },

Comments

axel.rutz created an issue. See original summary.

geek-merlin’s picture

Status: Active » Needs review
StatusFileSize
new1.11 KB

After learning the xml elemen naming rules i don't see a sanse in escaping.

Patch flying in that does the best we can do about that: Ignore properties with illegal names.

Status: Needs review » Needs work

The last submitted patch, 2: restws-2632992-2-commerce-price-field-raises-exception.patch, failed testing.

geek-merlin’s picture

Status: Needs work » Needs review

OK, the failing tests seem to be the same as without the patch:
https://www.drupal.org/node/1042186/qa

geek-merlin’s picture

StatusFileSize
new1.11 KB

re-testing #2

lokapujya’s picture

and a review of course.

geek-merlin’s picture

Title: commerce price field raises exception » Exception if a module declares a non-xml-compliant property name
Issue summary: View changes
Issue tags: -Needs issue summary update