Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Printers with \E in their name break findPrinter() #43

Closed
tresf opened this issue Jun 12, 2015 · 3 comments
Closed

Printers with \E in their name break findPrinter() #43

tresf opened this issue Jun 12, 2015 · 3 comments
Labels
Milestone

Comments

@tresf
Copy link
Contributor

tresf commented Jun 12, 2015

This bug is for qz-print versions 1.9.x and older (1.8.0 included) and breaks printer searching for search parameters containing backslash E (\E or JavaScript "\\E" also "\\\\E").


Example

If a printer shared on a Windows or Samba network with "E" as part of the host name, for example:

\\Elephant\printer

And you perform a search like this:

findPrinter("\\\\Elephant\\printer");

You will receive the following exception:

Exception in thread "Thread-26" java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index x ...
\b\Q\\Elephant\printer\E\b
      ^

This is caused by the special RegEx character \E being used within a Pattern match.


Work-around 1
Replace uppercase \E with lowercase \e:

   findPrinter(printerName.toLowerCase());

Reason

\e is not a reserved character, which allows printer searching to succeed

Work-around 2
Perform JavaRegex pattern escaping:

if (printerName.indexOf("\E") != -1) {
   printerName = printerName.replace(/\\E/, "\\E\\\\E\\Q");
}

Reason

This complicated combination of E's and Q's is the proper escaping technique and is a work-around until the applet is written to do this automatically

More information on these E's and Q's here:

http://stackoverflow.com/questions/11927452/what-does-these-special-characters-mean-in-java


Permanent Fix

The long term fix to this is to use Pattern.quote(printerName); internal to the applet, which will be corrected with 2.0.0.

-Tres

@tresf tresf added the bug label Sep 21, 2015
@tresf tresf added this to the 2.0 milestone Sep 21, 2015
@tresf
Copy link
Contributor Author

tresf commented Dec 28, 2015

@bberenz can we revisit this bug for 2.0? There's really no advantage in using RegEx in my opinion as programmers can do that client-side if they wish.

https://github.com/qzind/qz-print/blob/2.0/src/qz/printer/PrintServiceMatcher.java#L69:L129

@akberenz
Copy link
Member

Can you clarify how you want findPrinter to work in that case?
It seems like you want the method to return a PrintService for exact matches on the name string, and partial matches will be handled client side only from searching the printer list.

akberenz pushed a commit that referenced this issue Dec 30, 2015
@tresf
Copy link
Contributor Author

tresf commented Dec 31, 2015

FYI, closed via 5fc8e2a.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants