GithubHelp home page GithubHelp logo

Comments (8)

Propaganistas avatar Propaganistas commented on June 14, 2024

Are you sure nothing else has changed?
The debug screenshots of RawPhoneNumberCast point to the second case of the validation test:

['phone', '12345', 'min']

When running the following on a fresh Laravel instance, validation fails as expected:

validator(['phone' => '12345'], ['phone' => 'phone:BR'])->passes() // false

So in fact value 12345 should never have ended up in a model and hence never even invoke RawPhoneNumberCast...

I'm afraid the package works as designed and the root cause has to be found elsewhere... (Livewire? A controller? ...?)

from laravel-phone.

devajmeireles avatar devajmeireles commented on June 14, 2024

Are you sure nothing else has changed? The debug screenshots of RawPhoneNumberCast point to the second case of the validation test:

['phone', '12345', 'min']

When running the following on a fresh Laravel instance, validation fails as expected:

validator(['phone' => '12345'], ['phone' => 'phone:BR'])->passes() // false

So in fact value 12345 should never have ended up in a model and hence never even invoke RawPhoneNumberCast...

I'm afraid the package works as designed and the root cause has to be found elsewhere... (Livewire? A controller? ...?)

Hey! Thanks for your answer.

Nothing has changed other than updating the app to Laravel 10 prefixing Laravel Phone version 5.0.3. The application is made up of the TALL Stack, using Livewire to componetize parts of the system.

Tests work fine in Laravel 9.

After updating, I had done manual tests (QA) and realized that when entering a wrong value (from the country code) manually, let's say in an input, it gives the same error. I will update the app again today and post more information.

Tonight.

from laravel-phone.

devajmeireles avatar devajmeireles commented on June 14, 2024

@Propaganistas ,

Here is the demonstration: https://www.loom.com/share/9485e579382a48f5aea9f05807c601ae

I think there is some bug with the code, or you think I'm doing something wrong according to the video?

I also tried a different approach but I got the same error:

  1. Remove the Laravel Phone
  2. Upgrade Laravel to V10
  3. Install Laravel Phone

... Same error!

from laravel-phone.

devajmeireles avatar devajmeireles commented on June 14, 2024

I was not able to understand the reason, but I found a possible fix:

The getPossibleCountries always returns as BR even the number is something like: 12345 - that's the correct behavior.
image
image

The fix can be something like this:
image

from laravel-phone.

Propaganistas avatar Propaganistas commented on June 14, 2024

Thanks for the investigation. It clearly points out that there's a breaking change I forgot to mention in the release notes.

I'm not tempted to "fix" this scenario though. When using RawPhoneNumberCast you should ensure that only valid phone numbers make it into the model. Otherwise the cast will never be able to return a usable phone object when accessing the attribute. In v4 the cast gracefully returned an invalid phone object and that's why your tests passed, but now in v5 that behavior is aligned with E164PhoneNumberCast and it'll only accept valid phone numbers in order to avoid unexpected stuff later down the line.

So I think the way forward is to check how it's possible that the invalid value ends up in the model, and then prevent that.

from laravel-phone.

devajmeireles avatar devajmeireles commented on June 14, 2024

Thanks for the investigation. It clearly points out that there's a breaking change I forgot to mention in the release notes.

I'm not tempted to "fix" this scenario though. When using RawPhoneNumberCast you should ensure that only valid phone numbers make it into the model. Otherwise the cast will never be able to return a usable phone object when accessing the attribute. In v4 the cast gracefully returned an invalid phone object and that's why your tests passed, but now in v5 that behavior is aligned with E164PhoneNumberCast and it'll only accept valid phone numbers in order to avoid unexpected stuff later down the line.

So I think the way forward is to check how it's possible that the invalid value ends up in the model, and then prevent that.

Sorry, but that doesn't make sense to me. How do you explain the fact that the getPossibleCountries method always returns a valid country even if the getCountry() method of the PhoneNumber class returns null? In my tests, even for phones like (11) 91234 the getPossibleCountries method was able to work correctly detected that the phone is from Brazil.

from laravel-phone.

devajmeireles avatar devajmeireles commented on June 14, 2024

Thanks for the investigation. It clearly points out that there's a breaking change I forgot to mention in the release notes.

I'm not tempted to "fix" this scenario though. When using RawPhoneNumberCast you should ensure that only valid phone numbers make it into the model. Otherwise the cast will never be able to return a usable phone object when accessing the attribute. In v4 the cast gracefully returned an invalid phone object and that's why your tests passed, but now in v5 that behavior is aligned with E164PhoneNumberCast and it'll only accept valid phone numbers in order to avoid unexpected stuff later down the line.

So I think the way forward is to check how it's possible that the invalid value ends up in the model, and then prevent that.

"When using RawPhoneNumberCast you should ensure that only valid phone numbers make it into the model": in this test I'm creating contacts with valid phone numbers (via Faker) and after that I just try to change them with wrong numbers and this is where the problems occur.
image

from laravel-phone.

Propaganistas avatar Propaganistas commented on June 14, 2024

Sorry, but that doesn't make sense to me. How do you explain the fact that the getPossibleCountries method always returns a valid country even if the getCountry() method of the PhoneNumber class returns null? In my tests, even for phones like [(11) 91234](tel:(11) 91234) the getPossibleCountries method was able to work correctly detected that the phone is from Brazil.

It doesn't. That method solely exists to provide input for constructing a new phone object. It simply returns the parameters you hardcoded provide to the cast. "Coincidently" your test cases are Brazilian numbers and your cast parameter is BR.

$casts = [
    'phone' => RawPhoneNumberCast::class . ':BR',
];

so in case of an invalid (or any) number the cast attempts the following:

new PhoneNumber('12345', 'BR')

...and hence getCountry() returns null because in this particular example the construction leads to an invalid state.

from laravel-phone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.