-
Notifications
You must be signed in to change notification settings - Fork 22
Invalid Character in XML Error Prevents Order Creation #67
New issue
Have a question about this project? Sign up for a free Gi 8000 tHub 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
Comments
Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems): Should have added this, here is the stack trace between the Nwazet.Commerce code and the actual reported error:
|
Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems): I agree it is an invalid character and actually just finished trying SecurityElement.Escape, it didn't work. I am trying to set up a unit test that fails with an Invalid Character but it is hard to make an invalid character to even test. I wish PayPal would just strip them out (so I wouldn't have to try to) but then again I assume Stripe too could have invalid characters entered. Or, perhaps, this is just a one off scenario that I shouldn't even be trying to resolve. Will let you know what I find (and if you have further ideas I would love them). |
Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems): My client did and it is a legitimate order. It is only character in the street address which is coming in as an invalid character. Even though I can't paste it in here, it was a forward arrow --> (all one character) that seemingly was the issue. Here is an article: https://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/ that relates to the type of error and parses out all of these invalid characters. What I don't know is if this is something that the XML extensions should be taking care of (i.e. in Orchard native) or if it is something that each module should take care of (i.e. Nwazet.Commerce or my PayPal module)... |
Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems): Unfortunately, I don't know what charset it is coming from. Here is an image of what the Orchard log shows (since you can't type arrows in BitBucket): Here is how the IPN looks when viewed in a browser on PayPal website: But that same IPN when pasted into Notepad++ reveals the following: And finally in plain old Notepad it shows up as the arrow: So I know there is something there but no way to determine exactly what it is (other than an arrow). Part of me wonders if the XML parser calls it a 0x1A simply because it doesn't know what type of character it is. I too am concerned about failing gracefully as I have workflows tied to the order and none of them went out on this Order since it didn't publish properly. I happened to see it in the error logs. |
Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems): I agree, just wondering if this is something Orchard.Framework\ContentManagement\XmlHelper.cs should be doing for everyone of if this is something each module developer should concern themselves with. I have written a unit test to check for this:
The error is thrown on this line: var xmlString = el.ToString(SaveOptions.None); If we apply it in XmlHelper.cs then I believe we could do one check here:
But of course, there may be other points of issue and there may also be other ways people set XML attributes so I believe I am talking myself into sanitizing it just for my module. Any final thoughts you have are appreciated. |
Original comment by Bertrand Le Roy (Bitbucket: bleroy, GitHub: bleroy): I'd only change Xmlhelper after thoroughly checking for performance regression: this is an API that you'll see with a high frequency in profiles. But ideally, yes. I think the most important fix would be that any unhandled exception in order confirmation code would not prevent the order from going through if payment has already been processed. This seems like the most important. |
Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems): I haven't implemented the unhandled exception in order confirmation yet, but here is the code I am using in PayPal module to strip out invalid characters:
It is inefficient I am sure iterating over each character... don't see another way though. It does work though so that is a plus. I agree that if it can be deemed to be efficient and working it should make it's way to Nwazet.Commerce and finally to Orchard.Core. Get's me a patch I can put in place for today though. |
Originally reported by: Jeffrey Olmstead (Bitbucket: ems, GitHub: ems)
I have a user who has placed an Order via PayPal which feeds back to the Nwazet.Commerce.OrderService.CreateOrder method (so it seems it could also happen in Stripe). This individual is from the country of Lithuania and the street address they provided has an invalid character in it (at least as far as my American keyboard and ultimately XML is concerned). As a result, the following error is thrown:
System.ArgumentException: '�', hexadecimal value 0x1A, is an invalid character.
This error stems from:
Nwazet.Commerce.Models.OrderPart.PersistCustomer()
though it could stem from any of these methods. So my question is whether there is a single method / override we can apply to escape the invalid characters.
There is a discussion here: http://stackoverflow.com/questions/8331119/escape-invalid-xml-characters-in-c-sharp about invalid characters. I am wondering if we can use:
SecurityElement.Escape(text); (from System.Security)
to escape all our incoming text and pull these invalid characters out. Could it be implemented at the "ToAttr" method so it is automatically applied against all entries?
The text was updated successfully, but these errors were encountered: