tijsverkoyen / bpost

Other
28 stars 47 forks source link

Problem when using ampersand character in order line text #17

Closed hostep closed 7 years ago

hostep commented 9 years ago

Hi

We just had a problem creating a bpost order when one of the product names in the orderline contains an '&' character. This gives us the following error:

Error in request: cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '.*[^\s].*' for type 'OrderLineTextType'.

Code which fails:

$itemName = 'Something with an & character.';
$itemQty = 1;
$bpostOrder->addLine(new TijsVerkoyen\Bpost\Bpost\Order\Line($itemName, $itemQty));

Results in this XML:

  <tns:orderLine>
    <tns:text/>
    <tns:nbOfItems>1</tns:nbOfItems>
  </tns:orderLine>

Code to fix it:

$itemName = htmlspecialchars('Something with an & character.', ENT_XML1);
$itemQty = 1;
$bpostOrder->addLine(new TijsVerkoyen\Bpost\Bpost\Order\Line($itemName, $itemQty));

Results in this XML:

  <tns:orderLine>
    <tns:text>Something with an &amp; character.</tns:text>
    <tns:nbOfItems>1</tns:nbOfItems>
  </tns:orderLine>

But I don't think we should handle this in our own code, this should be handled by this library, no? Another fix might be to wrap the text in CDATA sections, but I didn't test that.

Thanks!