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

Adding square brackets in a shipping provider settings throws a JSON exception (Unexpected character encountered while parsing value) #544

Open
justin-nevitech opened this issue Jul 30, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@justin-nevitech
Copy link

Describe the bug

I am creating a custom shipping provider and I need to store a JSON value which is an array of objects in the shipping provider setting. I can get this working from the front-end, but when calculating the shipping rates it throws and JSON error. The same error happens when just adding square brackets into a normal text field setting and not even using any JSON:

image

If you inherit from ShippingProviderBase without using a settings class it works but if you try and use a settings class you get the error. Obviously without inheriting from the settings class you won't get the settings in the UI.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create a custom shipping provider with a simple text string setting in a settings class (as per https://docs.umbraco.com/umbraco-commerce/key-concepts/shipping-providers).
  2. Add the shipping method and make it available for you shipping country
  3. In the back office, enter square brackets '[]' into the shipping setting field
  4. Try and go through a checkout and it fails when calculating shipping rates.

image

Expected behavior

Shipping provider settings should be able to store and retrieve strings with square brackets (including JSON strings) without throwing an error.

Umbraco Commerce version:

13.1.6

@justin-nevitech justin-nevitech added the bug Something isn't working label Jul 30, 2024
@mattbrailsford
Copy link
Contributor

Fundamentally, shipping provider settings are stored in a dictionary and so Umbraco Commerce tries to convert that dictionary to an strongly typed object. It does this through JSON serialization and deserialization. It looks like having something that resembles JSON in a property value is causing confusion.

I'll have to dig into this, but just wondering if a coma separated string might do the trick? and if you then split it in your handler?

@justin-nevitech
Copy link
Author

Hi @mattbrailsford Thanks for coming back so quickly. I can get it working if I escape the JSON string which seems to get automatically unescaped in the shipping provider! I guessed it was something to do with the JSON serialization and deserialization but I was finding it hard to track down exactly. Thanks!

@mattbrailsford
Copy link
Contributor

Yea, I think we do do some auto deserialization of entry values so that probably fits with your findings of the string needing to be escaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants