softwaremill / softwaremill/sttp-model

Fix parsing of already-decoded URIs

Open
#310 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
45
Forks
33
Avg merge
3d 7h
Merged PRs (30d)
6

Description

I have issue with UriInterpolator attempting to decode part of URL which which is not originally encoded (just contains % character) or was already decoded.

Sample URL
https://storage.googleapis.com/realtyplusmag-news-photo/news-photo/108462.Welspun-Set-To-Acquire-70%-Debt-Of-Sintex-BAPL-2.jpg

Stack trace

URLDecoder: Illegal hex characters in escape (%) pattern - negative value
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - negative value
	at sttp.model.internal.Rfc3986$.decode(Rfc3986.scala:76)
	at sttp.model.UriInterpolator$UriBuilder$.sttp$model$UriInterpolator$UriBuilder$$decode(UriInterpolator.scala:665)
	at sttp.model.UriInterpolator$UriBuilder$.$anonfun$tokensToStringSeq$5(UriInterpolator.scala:620)
	at scala.collection.StrictOptimizedIterableOps.flatMap(StrictOptimizedIterableOps.scala:118)
	at scala.collection.StrictOptimizedIterableOps.flatMap$(StrictOptimizedIterableOps.scala:105)
	at scala.collection.immutable.Vector.flatMap(Vector.scala:113)
	at sttp.model.UriInterpolator$UriBuilder$.doToSeq$1(UriInterpolator.scala:618)
	at sttp.model.UriInterpolator$UriBuilder$.sttp$model$UriInterpolator$UriBuilder$$tokensToStringSeq(UriInterpolator.scala:632)
	at sttp.model.UriInterpolator$UriBuilder$Path$.pathFromTokens(UriInterpolator.scala:479)
	at sttp.model.UriInterpolator$UriBuilder$Path$.$anonfun$fromTokens$1(UriInterpolator.scala:475)
	at sttp.model.UriInterpolator$UriBuilder$.sttp$model$UriInterpolator$UriBuilder$$fromStartingToken(UriInterpolator.scala:565)
	at sttp.model.UriInterpolator$UriBuilder$Path$.fromTokens(UriInterpolator.scala:475)
	at sttp.model.UriInterpolator$.$anonfun$interpolate$1(UriInterpolator.scala:57)
	at scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
	at scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
	at scala.collection.immutable.List.foldLeft(List.scala:79)
	at sttp.model.UriInterpolator$.interpolate(UriInterpolator.scala:56)
	at sttp.model.UriInterpolator$UriContext.uri(UriInterpolator.scala:36)

Originally posted by @zikolach in https://github.com/softwaremill/sttp-model/issues/257#issuecomment-1762013121

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the sample URL, then start in sttp.model.UriInterpolator.scala at the decode path shown in the stack trace and inspect sttp.model.internal.Rfc3986.scala. Done means interpolation accepts the already-decoded path containing a literal percent sign without throwing the reported IllegalArgumentException.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.