GithubHelp home page GithubHelp logo

Comments (4)

n8han avatar n8han commented on July 19, 2024

likely relates to the fact that dispatch apparently going against the RFC and assuming UTF-8

Did you check the content headers?

nathan@x201 ~/Programming/giter8[master] $ curl -Is https://github.com/api/v2/json/blob/show/n8han/conscript.g8/c2ede99b688c84da2aa8179ad9f0ab3e9404635b|grep Content-Type
Content-Type: text/plain; charset=utf-8

Dispatch doesn't use its woefully incompliant default in this case; it's github that has assumed utf-8. Although, there's another header in there that looks interesting:

X-Content-Type-Options: nosniff

If that sniffing includes making an intelligent guess at the encoding, I say we use it. Better them guessing that us. If it's wrong it's wrong. What kind of a source file are you using a non-utf8 charset for, anyway? :)

from giter8.

eed3si9n avatar eed3si9n commented on July 19, 2024

It's actually just a fork of ngocdaothanh/xitrum.g8 to preserve its current state. It's some kind of keystore file that's causing this.

Dispatch doesn't use its woefully incompliant default in this case; it's github that has assumed utf-8.

Sorry. I stand corrected.

The problem starts when blob/full thinks it's a text/plain when the file is actually binary:


Then it declares utf-8, so that's the second problem.


$ curl https://github.com/api/v2/json/blob/show/eed3si9n/xitrum.g8/5a59c367d97af0fe3eddb4a59173b790a5164ace -I | grep Content-Type
...
Content-Type: text/plain; charset=utf-8

Should we just assume binary if we encounter MalformedInputException?

from giter8.

eed3si9n avatar eed3si9n commented on July 19, 2024

This seems to work...

  def write(repo: String, templates: Iterable[(String, String, String, String)], parameters: Map[String,String], base: File) = {
    templates foreach { case (name, hash, mime, mode) =>
      import org.clapper.scalasti.StringTemplate
      import java.nio.charset.MalformedInputException
      val f = new File(base, new StringTemplate(name).setAttributes(parameters).toString)
      if (f.exists)
        println("Skipping existing file: %s" format f.toString)
      else {
        f.getParentFile.mkdirs()
        (mime match {
          case Text(_) =>
            try {
              http(show(repo, hash) >- { in =>
                use (new FileWriter(f)) { fw =>
                  fw.write(new StringTemplate(in).setAttributes(parameters).toString)
                  Some(())
                }
              })
            }
            catch {
              case e: MalformedInputException => None
            }
          case binary => None
        }) getOrElse {
          http(show(repo, hash) >> { is =>
            use(is) { in =>
              use(new FileOutputStream(f)) { out =>
                def consume(buf: Array[Byte]): Unit =
                  in.read(buf) match {
                    case -1 => ()
                    case n =>
                       out.write(buf, 0, n)
                       consume(buf)
                  }
                consume(new Array[Byte](1024))
              }
            }
          })
        }
        setFileMode(f, mode)
      }
    }
    Right("Applied %s in %s" format (repo, base.toString))
  }

from giter8.

eed3si9n avatar eed3si9n commented on July 19, 2024

With the lastest v3 of Github API, the user is supposed to either request for json or raw in the Accept header. WIth raw, it no longer assumes UTF-8.

$ curl https://api.github.com/repos/eed3si9n/xitrum.g8/git/blobs/5a59c367d97af0fe3eddb4a59173b790a5164ace -H "Accept: application/vnd.github-blob.raw" -I | grep Content-Type
...
Content-Type: application/vnd.github-blob.raw

from giter8.

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.