Code Monkey home page Code Monkey logo

Comments (8)

BenFradet avatar BenFradet commented on June 12, 2024

hey, did you solve the issue in the end?

from github4s.

dev590t avatar dev590t commented on June 12, 2024

I have tested with gh.repos.searchRepos("47degrees/github4s", Nil), it doesn't work also.

The specification of searchRepos don't precise if / is accepted in its argument query. I'm not sure that is a bug, or is a expected behavior. So I have close the issue, and replace gh.repos.searchRepos("sterglee/scalalab", Nil) by gh.repos.searchRepos("scalalab", Nil) in my code.

But I feel it is a bug, params = Map("q" -> s"${encode(query, "utf-8")}+${searchParams.map(_.value).mkString("+")}"), this line in the implementation should allow searchRepo to accept / in query.

I reopen the issue.

from github4s.

BenFradet avatar BenFradet commented on June 12, 2024

curl https://api.github.com/search/repositories?q=sterglee%2Fscalalab does work so I agree there is an issue with the lib

from github4s.

josiah14 avatar josiah14 commented on June 12, 2024

I believe I've identified root cause.

RepositoryInterpreter.scala#L77 encodes the query parameters using a java.net.URLEncoder, which converts any /s into a %2F, which is no problem so far. The issue crops up when a second encoding happens at Http4sSyntax.scala#L62 via an org.http4s.Uri encoder, which then transforms the % in the %2F into a %25, transforming the entire section into %252F. The Github API does not know how to unravel multiple layers of encoding like this, and so it most likely treats the latter 2F as literal and part of the search pattern, which results in a successful search but with zero results.

from github4s.

josiah14 avatar josiah14 commented on June 12, 2024

java.net.URLEncoder appears to be redundant since every URL passed to the HttpClient gets encoded by Http4sSyntax.RequestBuilderOps.toUri anyway.

I think the best way to resolve this, therefore, is by stripping out the usages of java.net.URLEncoder and adding some tests to guard against a bug like this getting reintroduced in the future.

Via the changes in my branch, both of these now work:

scala> val searchRepos = gh.repos.searchRepos("47degrees/github4s", Nil)
val searchRepos: cats.effect.IO[github4s.GHResponse[github4s.domain.SearchReposResult]] = IO(...)

scala> searchRepos.unsafeRunSync()
val res0: github4s.GHResponse[github4s.domain.SearchReposResult] = GHResponse(Right(SearchReposResult(1,false,List(Repository(53343599,github4s,47degrees/github4s,User(60125571,47degrees,https://avatars.githubusercontent.com/u/60125571?v=4,https://github.com/47degrees,None,None,None,None,None,None,Some(https://api.github.com/users/47degrees/followers),Some(https://api.github.com/users/47degrees/following{/other_user}),Organization,None,None,None),false,false,false,RepoUrls(https://api.github.com/repos/47degrees/github4s,https://github.com/47degrees/github4s,git://github.com/47degrees/github4s.git,[email protected]:47degrees/github4s.git,https://github.com/47degrees/github4s.git,https://github.com/47degrees/github4s,HashMap(tags_url -> https://api.github.com/repos/...
scala> val searchRepos = gh.repos.searchRepos("repo:47degrees/github4s", Nil)
val searchRepos: cats.effect.IO[github4s.GHResponse[github4s.domain.SearchReposResult]] = IO(...)

scala> searchRepos.unsafeRunSync()
val res1: github4s.GHResponse[github4s.domain.SearchReposResult] = GHResponse(Right(SearchReposResult(1,false,List(Repository(53343599,github4s,47degrees/github4s,User(60125571,47degrees,https://avatars.githubusercontent.com/u/60125571?v=4,https://github.com/47degrees,None,None,None,None,None,None,Some(https://api.github.com/users/47degrees/followers),Some(https://api.github.com/users/47degrees/following{/other_user}),Organization,None,None,None),false,false,false,RepoUrls(https://api.github.com/repos/47degrees/github4s,https://github.com/47degrees/github4s,git://github.com/47degrees/github4s.git,[email protected]:47degrees/github4s.git,https://github.com/47degrees/github4s.git,https://github.com/47degrees/github4s,HashMap(tags_url -> https://api.github.com/repos/...

from github4s.

dev590t avatar dev590t commented on June 12, 2024

I think the best way to resolve this, therefore, is by stripping out the usages of java.net.URLEncoder and adding some tests to guard against a bug like this getting reintroduced in the future.

@josiah14 , Is it possible to use the type system of Scala to guard against a bug like this?
For instance

case class NotEncodedQuery(value : String)
val queryString : NotEncodedQuery = ???
val verbatimQuery = URI(Query.unsafeFromString(Uri.encode(queryString.value)))

from github4s.

josiah14 avatar josiah14 commented on June 12, 2024

@dev590t That's an interesting an worthwhile thought. I'm not sure there's a way to ensure the query string is not encoded though without incurring extra runtime overhead since the query string itself is provided by the library consumer. It would make sense to me to ensure we aren't multi-encoding the string within the library itself, but to assume that just because we haven't encoded it yet that the end user hasn't provided an already encoded string may be a bit presumptuous and thus difficult to really wrap into the type system in a way that seems to indicate we know for sure whether something we've received is encoded or not.

@Daenyth Do you have any input on this? I'm hoping I'm wrong and there's a reasonable way to wrap this sort of validation into the type-system without overhead (or with little-enough overhead that it's justified).

from github4s.

Daenyth avatar Daenyth commented on June 12, 2024

I don't think it's worth making the types more complex to fix this; we can just have a unit test in this case

from github4s.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.