0

I know that there are dozens of similar topics, but I didn't found smth useful to answer my question.

Suppose I have an url http://example.com/a/b?param1=1&param2={"a": "b"}&param3="&=+%"

+ and = signs don't get encoded when using apache UriUril.encodeQuery. When using URLEncoder.encode they do get encoded but in that case I have to encode each parameter value individually(so I need to get a map of parameters and their values). Simply splitting the url string on & or = doesn't work in this case as you can see.

So how this task can be overcomed with less effort applied?

2 Answers 2

1

By using URI templates.

Using URI templates what you have is called an associative array.

There exist implementations in Java; one of them is mine (sorry for the self ad).

Sign up to request clarification or add additional context in comments.

7 Comments

it's good when you know what is a parameter name and what is a parameter value. But when this string is produced by user it becomes more complicated
Sorry, I don't get what you mean; can you be more precise?
users pass url string to application, the task is to correctly parse parameters as they can contain any symbols
Wait, this is more and more confusing; are the user strings already encoded or not?
they are not. If I have a collection of paremeters and their values I can easily encode them(which is my primary goal)
|
0

I've found the solution to my problem by preparing appropriate regular expression to parse parameters and their values. Maybe the solution is not so elegant as it has to be, but it solves my problem. So, supposing that {}are enclosing symbols that may conatin any symbols inside and "" are also such symbols(except they can't contain themselves inside) the regexp looks like: ((\w+)=(\{.*?\}(?=&)|\{.*\}|".*"|\w+))&{0,1}

Input for such regexp must be query string of url. In each 2-nd group there will be parameter name and in each 3-rd group - parameter value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.