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

Wrong currency extracted in case of long strings containing "$" #48

Closed
croqaz opened this issue Mar 8, 2021 · 5 comments
Closed

Wrong currency extracted in case of long strings containing "$" #48

croqaz opened this issue Mar 8, 2021 · 5 comments

Comments

@croqaz
Copy link
Member

croqaz commented Mar 8, 2021

These examples:

Price.fromstring('180', currency_hint='$${product.price.currency}')
Price.fromstring('180', currency_hint='qwerty $')
Price.fromstring('180', currency_hint='qwerty $ asdfg')

All of them return Price(amount=Decimal('180'), currency='$').

From what I understand in the code, this happens in _search_safe_currency:

_search_unsafe_currency('asd $ qwe')
# <re.Match object; match='$'>

Would it be in the scope of the library to match the currency more strictly?
This would cover the use-case when we are pretty sure that the currency hint is exact, not fuzzy.

@Gallaecio
Copy link
Member

I’m personally not sure this is something price-number should aim to address. It feels to me like the code calling price-parser here should be responsible of cleaning up what it passes to currentcy_hint before it is passed.

@croqaz
Copy link
Member Author

croqaz commented Mar 9, 2021

Makes sense. We will see what we can do.
I think it's safe to close for now.

@croqaz croqaz closed this as completed Mar 9, 2021
@lopuhin
Copy link
Member

lopuhin commented Mar 9, 2021

It feels to me like the code calling price-parser here should be responsible of cleaning up what it passes to currentcy_hint before it is passed.

But then maybe price-parser shouldn't alter the original currency?

@Gallaecio
Copy link
Member

But then maybe price-parser shouldn't alter the original currency?

I’m not sure that’s happening here, at least in the examples from the issue description, where there’s only the currency hint being passed, no original currency is specified otherwise.

@lopuhin
Copy link
Member

lopuhin commented Mar 9, 2021

Sure, let us look a bit more into it and then we can decide if the fix makes sense in the context of price-parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants