Skip to content

BUG: Support \t, \r on raw usage, they are printable - #1355

Open
erikn69 wants to merge 2 commits into
mike42:developmentfrom
erikn69:patch-3
Open

BUG: Support \t, \r on raw usage, they are printable#1355
erikn69 wants to merge 2 commits into
mike42:developmentfrom
erikn69:patch-3

Conversation

@erikn69

@erikn69 erikn69 commented Sep 23, 2024

Copy link
Copy Markdown

It seems that this package was forgotten by @mike42

CRLF: In raw usage the plugin removes the \r(carriage returns) assuming that they are all from windows
but in windows they should only be deleted when they are followed by a \n(line feed)

\t: raw usage removes printable horizontal tabs

@mike42

mike42 commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Hey, this issue was posted to another PR I'm working on. It's not clear to me why a code change is required here. Could you please explain some of the basics of the issue, eg:

  • what you are trying to do
  • what printer you have (to confirm it is ESC/POS - available documentation is always a plus)
  • what code you are running
  • what the output is, and why it should be different.

That code is for sending ASCII to a printer as a fallback if we have not figured out character encoding, and is not really intended to funnel control characters through, since they will behave differently between printers.

This library has very wide compatibility considerations, so passing through new control characters on this code path could cause surprising results if somebody else was relying on them being filtered out.

if ($c == "\r") {
/* Skip past Windows line endings (raw usage). */
if ($c == "\r" && substr($text, $i + 1, 1) == "\n") {
/* Skip past Windows line endings CRLF (raw usage). */

@erikn69 erikn69 Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, this is for raw mode(writeTextRaw(string $text));
it handles the \r characters as CRLF(windows),
If there is only a \r(CR), it yields a false positive for an LF.
Now it check \r\n(CRLF)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so passing through new control characters on this code path could cause surprising results if somebody else was relying on them being filtered out.

Only on raw usage, but it could be for a major release

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/ht.html

\t (HT) is only meaningful if horizontal tab stops have been configured (typically with the ESC D command). Otherwise, its behavior is implementation-dependent and many printers simply ignore it.

https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/cr.html

\r (CR) is not equivalent to \n (LF). On Epson ESC/POS printers, the behavior of CR depends on the printer configuration (e.g. whether Auto Line Feed is enabled). On many thermal printers with a serial interface, CR is ignored, while LF is the recommended way to advance to the next line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s been a long time; I no longer have access to that printer or the code, but this worked well in production.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and is not really intended to funnel control characters through,

In my opinion, it validates printable characters.

if ($num == 10) { // New-line (printer will take these)
return true;
}
if ($extended && $num > 127) {
return true;
}

Maybe using $extended also?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$extended is true only on writeTextRaw(string $text), that would reduce potential problems
HT is ignored if the columns are not configured.
CR is ignored if AUTO LINE FEED is not configured.

} elseif (self::asciiCheck($c, true)) {
$outp[$j] = $c;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants