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

Workaround for some '&' char encoding #1410

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

korshaknn
Copy link
Contributor

@korshaknn korshaknn commented Apr 21, 2022

more details in #1409
this PR fixes the case when there is a name like "me & you". Need a better solution to fix encoding in general

& char in Utf-8 is %26.
we can't replace it in the next block:

if (waypointNames() != null) {
      sb.append(String.format("&waypoint_names=%s", waypointNames()));
}

because if we do something like this

sb.append(String.format("&waypoint_names=%s", waypointNames().replace("&", "%26")));

we will get invalid chars while building a final Url URL(encodedUri.toASCIIString())
because %26 will be encoded to %2526 (% char is %25 in Utf-8)
and we will get invalid %2526 instead of %26.

That's why I replace the char on a final step

URL(encodedUri.toASCIIString().replace("%20&%20", "%20%26%20"));

I check for start+end space characters (%20) not to affect & chars that are used to connect url params.

@korshaknn korshaknn added the Bug label Apr 21, 2022
@korshaknn korshaknn requested a review from a team as a code owner April 21, 2022 11:32
@korshaknn korshaknn self-assigned this Apr 21, 2022
@korshaknn korshaknn force-pushed the knn_waypoint_names_encoding_fix branch from 2d26931 to b23bcef Compare April 21, 2022 11:58
@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #1410 (b23bcef) into main (a0045aa) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #1410   +/-   ##
=========================================
  Coverage     75.23%   75.23%           
  Complexity      920      920           
=========================================
  Files           125      125           
  Lines          3957     3957           
  Branches        645      645           
=========================================
  Hits           2977     2977           
  Misses          706      706           
  Partials        274      274           
Impacted Files Coverage Δ
.../mapbox/api/directions/v5/models/RouteOptions.java 83.69% <100.00%> (ø)

@korshaknn korshaknn merged commit 82fc6c1 into main Apr 21, 2022
@korshaknn korshaknn deleted the knn_waypoint_names_encoding_fix branch April 21, 2022 13:03
@LukasPaczos LukasPaczos changed the title Fix waypointNames '&' char encoding Workaround for some '&' char encoding Apr 22, 2022
RingerJK added a commit that referenced this pull request Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants