-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Backslash Escaping of Pipes #65
Open
boppy
wants to merge
2
commits into
p-e-w:master
Choose a base branch
from
boppy:allow-pipe-escape
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,10 @@ function parseLine(lineString) { | |
|
||
let separatorIndex = lineString.indexOf("|"); | ||
|
||
while(lineString.substr(separatorIndex-1,1) == '\\'){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails if Also, please use double quotes like the rest of the code. |
||
separatorIndex = lineString.indexOf("|", separatorIndex+1); | ||
} | ||
|
||
if (separatorIndex >= 0) { | ||
let attributes = []; | ||
try { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized there is a much cleaner solution that also covers all corner cases: Just replace
indexOf
in this line with a regular expression search using negative lookbehind, and you're done (it will have to be a GLib regex because JavaScript doesn't support lookbehind).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. Unluckily there are not all C functions available in the JS frontend, so I have not been able to use
g_regex_split_full
withmax_tokens
, but insteadsplit
ed and rejoin
ed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split_full
is available, it's just not a static function. You first need to create a Regex object withregex_new
, then you should be able to callsplit_full
on it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but I need some more input. Using
gives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, seems like it's
GLib.Regex.new
. For the documentation to be any less clear it would have to be written in hieroglyphs... 😞There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it works for me:
a = GLib.Regex.new("a", 0, 0)
, press Entera.split_full()
, press EnterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right. Because the documention is that great, they use lazy loading for the functions, so nobody can ever find anything helpful in debugging...
I - again - feel like a total noob to programming... even with all your hints I'm far away of getting it to work...
I tried:
This always gives
Cannot convert string to array of 'utf8'
even for lines like---
orOTP
. After manual split, empty Strings work, afer locale-convert the converted String is empty... For sure all my shell files are UTF8 encoded - In fact "OTP" or "---" do not differ much in any encoding out there...Do you have any "better" source for GLib/Gnome/JavaScript? I am not able to find anything resilient...
Log extract:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the particular problem is here, but I very much know this feeling of being stuck. Argos has less than 1000 lines of code in total, but some of those lines took many hours to write. As you mention, some things are just flat out undocumented, and the Gjs bindings also have bugs (including memory bugs; I managed many times to crash GNOME Shell from JavaScript).
To create Argos, I used a combination of Valadoc, whatever outdated/incomplete Gjs documentation was available at that time, and the GNOME Shell source code. I tried to learn from other Shell extensions, but quickly found the overwhelming majority of them to be riddled with errors and just have abysmal code quality in general. At the end of the day, very little existing code was of any help at all, and most of the progress came from trial-and-error in Looking Glass.
So I'm afraid there is no silver bullet here, and lots of things that are ultimately beyond your control. If you can't work this out, no worries. I don't consider this feature to be that important and I believe BitBar doesn't have it either. It is up to you if you want to pursue this further. But I must be clear that I won't be merging any hacks, or any code whose behavior we don't completely understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could possibly distill the problem into a minimal example and ask on https://unix.stackexchange.com / https://stackoverflow.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the question of the day is: Do you feel that my
split-shift-join
is hacky (I skip the "not understanding" part because I'm in doubt that you are not understanding this... ^^)? I think it's okay since it is (to my believe) the only way to do a limited split with vanilla js (since thelimit
er on vanilla-.split
is not working as in python or php, where splitting never "shortens" the input). It's okay for me that GLib tries to provide a better way of splitting, but since it's not working as expected, I think going back to the roots (=vanilla) is the best way possible.I also feel that skipping the
else
case while parsing the line is enhancing the readability of the code.@catb0t Good idea, but since there seem not to be that many gnome-js devs out there (otherwise "we" might already have partnered to give the gnome-js-dev team a litte visit ;)), I am not sure to gain any profit. Nevertheless I will compile a question and ask over there.