gmuth / ipp-client-kotlin

A client implementation of the ipp protocol written in kotlin
MIT License
75 stars 10 forks source link

URISyntaxException when using printer url with URI encoded whitespaces #13

Closed ocindev closed 1 year ago

ocindev commented 1 year ago

When trying to connect to a ipp printer whose URI contains encoded whitespaces, e.g http://localhost/PDF%20Printer/.printer, the library throws an URISyntaxException when trying to sent the ipp request. This is due to the IPPClients method toHttpUri using the getPath from java.net.URI which delivers the decoded path version.

fun toHttpUri(ippUri: URI) = with(ippUri) {
        val scheme = scheme.replace("ipp", "http")
        val port = if (port == -1) 631 else port
        URI.create("$scheme://$host:$port$rawPath")
 }

As a following result the call of URI.create("$scheme://$host:$port$path") throws the afformentioned exception.

As a solution one should use the java.net.URI::getRawPath

gmuth commented 1 year ago

Hi Nico, thanks for your report and pull request. How do you manage to setup a printer (in CUPS?) with queue name including a white space? I am trying to fully reproduce the issue and want to print to such a queue. The Apple CUPS of my macOS does replace " " with "_" when I setup new printers. Which IPP Server implementation do you connect to?

ocindev commented 1 year ago

Hi Gerhard, our client did setup a printer behind Microsofts Internet Printing Service based on their IIS stuff. The resulting network URI did contain the full printer name with whitespaces, e.g http://127.0.0.1/printers/HP Color LaserJet M553 PCL 6/.printer. Locally on my MacBook using CUPS i wasnt able to reproduce this neither. So this might be some kind ugly Microsoft Windows thing.

ocindev commented 1 year ago

Short update. Just checked with a colleague. Windows indeed does NOT restrict the usage of whitespaces in network share names for printers. So this just seems to be an edge case :)