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

UK Postcode still generating 2 spaces between elements #182

Closed
themarkdavies opened this issue Mar 6, 2014 · 1 comment
Closed

UK Postcode still generating 2 spaces between elements #182

themarkdavies opened this issue Mar 6, 2014 · 1 comment

Comments

@themarkdavies
Copy link

Hi, this is my first GITHUB post and I am new to ruby so please bear with me. I have looked through the issues logged about faker and have spotted this issue reported previously and fixed. However, having checked I am on the latest version of faker (1.2.0) I am still getting these problems.

My development environment is as follows:

  • ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
  • Rails 4.0.2
  • faker (1.2.0)
  • i18n (~> 0.5)

If I run IRB and setup the local for UK then generate a postcode you can see below that it has produced a postcode with two spaces:

rails console
Loading development environment (Rails 4.0.2)
1.9.3p448 :001 > Faker::Config.locale = 'en-gb'
=> "en-gb"
1.9.3p448 :002 > Faker::Address.postcode
=> "WM5 6JY"

Having run this several more times I get the following results:

=> "YS3 8BA" [ Invalid ]
=> "I78 6DJ" [ Invalid ]
=> "YH7 4FN" [ Valid ]
=> "S6H 9PU" [ Valid ]
=> "Y4V 9YP" [ Valid ]
=> "ZE1 1LN" [ Valid ]
=> "W1 2QB" [ Invalid ]
=> "GD7X 7GA" [ Invalid ]
=> "S35 7AL" [ Invalid ]
=> "W9N 0JR" [ Valid ]
=> "G0 5BJ" [ Valid ]
=> "TL8 5BL" [ Invalid ]
=> "YF9P 3DJ" [ Invalid ]
=> "YG9W 9LL" [ Valid ]

The results are bizarre because it does produce both valid and invalid formats that follow the same postcode standards.

For example,
"YS3 8BA" and "YH7 4FN" are both in the format AAN NAA, yet one has a single space and the other has 2 spaces.

"GD7X 7GA" and "YG9W 9LL" are both in the format AANA NAA and again one has a single space and the other has 2 spaces.

I can get around this using the squeeze method as suggested by one of the other posters but thought I should report the bug because the fix doesn't seem to have worked.

Faker::Address.postcode.squeeze(" ")

I checked that the regular expression you are using in Faker to see if it would return invalid for postcodes with 2 spaces (in the correct format). The regex you are using is as follows:

[A-PR-UWYZ][A-HK-Y]?[0-9][ABEHMNPRVWXY0-9]? [0-9][ABD-HJLN-UW-Z]{2}

I checked this using Rubular and Expresso tools using the postcode "US6P 7AD" and both indicated this does not match the regex. Removing the space does produce a valid match.

@stympy
Copy link
Contributor

stympy commented Mar 9, 2014

The fixes hadn't yet been released as a gem. I have just pushed the 1.3.0 version of the gem which includes these fixes, so you should be good to go.

@stympy stympy closed this as completed Mar 9, 2014
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

2 participants