Skip to content

Conversation

@lingo
Copy link

@lingo lingo commented Sep 5, 2025

An alternate implementation of #65
to fix #152

Given that the existing pull request has sat there since 2018(?) perhaps this alternative is accepted?

@lingo lingo changed the title Allow Backslash Escaping of Pipes #65 Allow Backslash Escaping of Pipes #152 Sep 5, 2025
{
separatorIndex = lineString.indexOf("|", separatorIndex);
if (separatorIndex === 0 || lineString[separatorIndex-1] != '\\') {
// found a non-escaped pipe symbol
Copy link
Collaborator

@mwilck mwilck Sep 8, 2025

Choose a reason for hiding this comment

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

What if lineString[separatorIndex-2] is a backslash, too? 'one\\|two' should be split into ['one\', 'two'].

#65 has the same issue, AFAICT. Actually this kind of quoting is tricky to get right.

Copy link
Author

Choose a reason for hiding this comment

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

Good point. I was thinking to avoid some of the complexities of the regex engine and syntax, but it's true this also avoids some of the complexities of the problem itself!

Copy link
Author

Choose a reason for hiding this comment

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

I've updated the code to handle escaping better, hope this is useful.

Copy link
Author

Choose a reason for hiding this comment

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

My test file:

#!/usr/bin/env -S tail -n+2
Test
---
Try me one\|   bash='zenity --info --text=Ok' terminal=false
Try me one\\|  bash='zenity --info --text=Ok' terminal=false
Try me one\\\| bash='zenity --info --text=Ok' terminal=false

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.

Allow for escaping |

2 participants