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

Allow decimals in the local alert radius. #5205

Merged
merged 2 commits into from
Oct 16, 2024
Merged

Allow decimals in the local alert radius. #5205

merged 2 commits into from
Oct 16, 2024

Conversation

dracos
Copy link
Member

@dracos dracos commented Oct 4, 2024

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 67.74194% with 10 lines in your changes missing coverage. Please review.

Project coverage is 82.34%. Comparing base (f122336) to head (8789d51).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
perllib/FixMyStreet/App/Controller/Rss.pm 68.42% 5 Missing and 1 partial ⚠️
web/cobrands/fixmystreet/fixmystreet.js 0.00% 2 Missing ⚠️
perllib/FixMyStreet/App/Controller/Alert.pm 85.71% 0 Missing and 1 partial ⚠️
perllib/FixMyStreet/Script/Alerts.pm 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5205   +/-   ##
=======================================
  Coverage   82.34%   82.34%           
=======================================
  Files         409      409           
  Lines       31999    32002    +3     
  Branches     5096     5096           
=======================================
+ Hits        26349    26352    +3     
+ Misses       4149     4148    -1     
- Partials     1501     1502    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dracos dracos requested a review from nephila-nacrea October 8, 2024 09:22
perllib/FixMyStreet/App/Controller/Alert.pm Show resolved Hide resolved
$distance = 150 if $distance > 150; # Match Gaze maximum
return $distance;
return $distance + 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the + 0 needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure it is internally a number, not a string of a number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in my experience, Perl just 'does the right thing' and treats it as a string or a number based on the context. Was there a specific instance where not having it explicitly be a number was causing bugs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does do that, but in a non-English locale a decimal number could eg stringify with a comma, not a point. I know we call in_gb_locale above, but if the input is already converted to a string before that point (with a comma), that call won't change anything, it's already a string. So we need to make sure it's a number before it gets there.
I'm not sure it /actually/ matters here, there's no use locale but I think that can have spooky action at a distance so better to be safe.

@@ -111,7 +111,7 @@ sub local_problems_pc_distance : Path('pc') : Args(2) {

}

sub local_problems_dist : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)/(\d+)$') {
sub local_problems_dist : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)/(\d+(?:\.\d+)?)$') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex here checks for a full stop, but in get_distance in the file above, it also checks for a comma. Why is there not one here?

Also, where is local_problems_dist called from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, get_distance allows people to enter decimals as commas, but then it's always a decimal point by the time it reaches the URL (and then here).
RSS feeds of that form come here directly, it's a controller, so not called from anywhere. The Alert page will construct an RSS in this form if you supplied a distance there.

$distance = 150 if $distance > 150; # Match Gaze maximum
return $distance;
return $distance + 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in my experience, Perl just 'does the right thing' and treats it as a string or a number based on the context. Was there a specific instance where not having it explicitly be a number was causing bugs?

@dracos dracos merged commit 8789d51 into master Oct 16, 2024
19 of 20 checks passed
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

Successfully merging this pull request may close these issues.

2 participants