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

Handle phone numbers that start with "%2B" #610

Merged
merged 3 commits into from
Nov 1, 2024

Conversation

crummy
Copy link
Contributor

@crummy crummy commented Oct 28, 2024

Problem

I've generated a Java SDK for the signal-cli-rest-api with liblab. They parse their URL arguments with URLEncoder.encode(value, StandardCharsets.UTF_8.toString());, which turns +1234 into %2B1234. Thus, when I use the client to query the API, I get a 400 error because /v1/groups/%2B1234 is malformed.

Solution

Escape the number when parsing it.

Comments

I have never written Go code before, so feel free to point out any problems here!

Googling, it seems like + is actually allowed in part of the URL - it must be escaped if following a ?, and can be escaped before. So it seems reasonable to handle both ways.

@crummy crummy changed the title Handle phone numbers that start with "%25" Handle phone numbers that start with "%2B" Oct 28, 2024
number, err := url.PathUnescape(c.Param("number"))
if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - malformed number"})
}
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the PR!

In general it looks good, the only thing that is missing is a return in case a malformed number is provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed.

@bbernhard
Copy link
Owner

Thanks a lot!

@bbernhard bbernhard merged commit 181f781 into bbernhard:master Nov 1, 2024
1 of 2 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