question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support unencoded reserved characters in path segments

See original GitHub issue

Some time ago, we had support for MatrixVariables added to Spring Cloud OpenFeign, using this processor.

This implementation works ok while sending requests to Spring REST controllers that can handle incorrectly encoded ; and = characters for matrix variables. However, an issue has been reported here that causes problems for servers that will not handle incorrect encoding of matrix variable reserved characters.

Basically, since matrix variables can appear in any path segment, they are handled by us as path params, with values stored in indexToExpander and get fully pct-encoded by feign-core, including their special characters, so we get /server/matrixParams%3Baccount%3Da%3Bname%3D instead of /server/matrixParams;account=a;name=n.

It looks like an issue that can only be addressed within feign-core and not as part of our integration. I could work on a fix if that’s fine with you. An idea that comes to mind is to introduce some kind of markers, say {{}} that would surround characters that should not be encoded within expanded path param chunks, but I’m also open to work on any other solution that the team might prefer. Let me know what you think about it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kdavisk6commented, Nov 8, 2021

@OlgaMaciaszek @oliverlockwood I’ve added #1537 to enable support for Path Style parameters. Expressions that start with semi-colons ; are treated as path style, a.k.a matrix style parameters.

Examples

{;who}             ;who=fred
{;half}            ;half=50%25
{;empty}           ;empty
{;list}            ;list=red;list=green;list=blue
{;map}            ;semi=%3B;dot=.;comma=%2C

You no longer need a custom expander for this type of expression, as this change exposes PathStyleExpression as an Expander for use.

For example, in MatrixVariableParameterProcessor:

@Override
public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) {
	int parameterIndex = context.getParameterIndex();
	Class<?> parameterType = method.getParameterTypes()[parameterIndex];
	MethodMetadata data = context.getMethodMetadata();
	String name = ANNOTATION.cast(annotation).value();

	checkState(emptyToNull(name) != null, "MatrixVariable annotation was empty on param %s.",
			context.getParameterIndex());

	context.setParameterName(name);
        data.indexToExpander().put(parameterIndex, new PathStyleExpression(name, null);
	return true;
}

If this meets your needs, please let me know and we’ll work on getting it released.

1reaction
kdavisk6commented, Apr 22, 2021

All, thank you for your patience. I understand the issue and it’s importance to you all. The root of the issue is that our URI template expression handling is very simple and limited. I have an idea where we can move expansion of custom expanders deeper into the parsing. This would require expanders to manage pct-encoding directly however, which may break existing integrations.

I’d like more time to think it through.

Read more comments on GitHub >

github_iconTop Results From Across the Web

(Please) Stop Using Unsafe Characters in URLs
Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, ......
Read more >
How to include number (hash) character # in path segment?
For path segments, reserved characters such as / and % are not encoded. For path segments, illegal characters such as spaces are encoded....
Read more >
Using URL encoding to handle special characters in a ...
In this article, we will walk through a scenario where exceptions are thrown if such a URI with special character is not handled...
Read more >
RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
A URI is a sequence of characters from a very limited set: the letters of the basic Latin alphabet, digits, and a few...
Read more >
URI's, URL's, and Special Characters — Vidispine REST API 5 ...
Path segments are encoded using RFC3986. · Non-ASCII characters are encoded in UTF-8, and do not have to be percent encoded · Percent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found