-
-
Notifications
You must be signed in to change notification settings - Fork 717
Add initial support for an escape character #2354 #2361
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2361 +/- ##
=========================================
+ Coverage 7.96% 8.10% +0.13%
=========================================
Files 143 143
Lines 10369 10382 +13
=========================================
+ Hits 826 841 +15
+ Misses 9543 9541 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Thanks :)
I think everything works, good job!
As far as I can tell you are using positive_offset
and negative_offset
to keep track of the difference in indices between cfg_value
and the returned value (and escaped_value
).
Now, I don't think it's necessary to generate the escaped string for when there are unescaped backslashes. In that case, it would be possible to use the same string object for searching and replacing without having to keep track of index differences.
There are also a few other things that should be in this PR:
- The manpage for the polybar config should be updated to include information about the escape character. The file is in
doc/man/polybar.5.rst
and the changes should go in theKeys
section. - New tests for the new function as well as some added testcases for the
ParseLineKeyTest
that include backslashes. The tests belong intests/unit_tests/components/config_parser.cpp
- A changelog entry describing your changes, including breaking changes: https://github.com/polybar/polybar/blob/master/CONTRIBUTING.md#changelog
Let me know once this is ready for review again. Also, the CI docs fail isn't your fault, there seems to be an issue with an ubuntu mirror. |
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.
Code looks good now. Just some minor adjustments.
Also, I'm curious why you are using find_first_of
instead of find
Also, it seems that CI is also having a segfault. I was also able to reproduce it sometimes. Looking at the coredump, it looks like it's something inside the logger, but the actual errors are kind of weird. I suspect that it's because you used string concatenation for the log message. |
No reason, changed it to
Printf tokens didn't help. |
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 think I found the issue with the segfault. It was undefined behavior in test code I wrote.
I pushed a fix in #2364.
After that is merged we can see if there are any other CI issues with your code.
But other than that, I think we can merge this soon.
Can you rebase against master so that your branch includes my fix? |
If we remove the |
Everything looks good now, but I can't merge yet because there is still a merge conflict (though it wasn't there a minute ago). You need to resolve it before I can merge this. |
I am not sure if I am missing something but Upstream being your polybar repo. |
I think you need to to |
I think 6b21044 messed things up a bit |
Sorry for breaking things, still get confused by git sometimes. |
Add a config parser method which, for now, deals only with escaping the literal backslash character and logs an error message to inform the user of the coming change. The error message includes a properly escaped value for the user. As a result of introducing an escape character('\'): - Warn the user of any unescaped backslashes, as they will not be treated as a literal character in the future - For now, still treat a single backslash as a literal character - Treat two consecutive backslashes as a single properly escaped literal backslash Also: - Add documentation about the escape character to polybar(5) manpage - Add info about the escape character to changelog - Add testcases for ParseLineKeyTest - Add new test ParseEscapedValueTest Resolves: First step in polybar#2354 Improve value parsing - Take value arg in as an rvalue reference and move parsed value back - Remove unnecessary if statement - Rename function - Improve error message - Improve function description - Format Add escape character documentation to manpages Add information about the escape character to the polybar(5) manpage. Add info about the esacape character to changelog Add test cases for ParseLineKeyTest Fix ParseLineKeyTest test cases Also make config parser method parse_escaped_value private. Add tests for escaped_value_parser method Also remove unsued include statement Simplify parse_escaped_value in config_parser Remove unnecessary escaped value generation, so we do not have to keep track of index differences. Fix ParseEscapedValueTest test cases Fix parse_escaped_value Add more test cases for ParseLineKeyTest Update CHANGELOG.md Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> Adress review - Adjust documentation - Small code changes Improve parse_escaped_value Add initial support for an escape character Add a config parser method which, for now, deals only with escaping the literal backslash character and logs an error message to inform the user of the coming change. The error message includes a properly escaped value for the user. As a result of introducing an escape character('\'): - Warn the user of any unescaped backslashes, as they will not be treated as a literal character in the future - For now, still treat a single backslash as a literal character - Treat two consecutive backslashes as a single properly escaped literal backslash Resolves: First step in polybar#2354 Improve value parsing - Take value arg in as an rvalue reference and move parsed value back - Remove unnecessary if statement - Rename function - Improve error message - Improve function description - Format Add info about the esacape character to changelog Add test cases for ParseLineKeyTest Fix ParseLineKeyTest test cases Also make config parser method parse_escaped_value private. Add tests for escaped_value_parser method Also remove unsued include statement Simplify parse_escaped_value in config_parser Remove unnecessary escaped value generation, so we do not have to keep track of index differences. Fix ParseEscapedValueTest test cases Add more test cases for ParseLineKeyTest Adress review - Adjust documentation - Small code changes Remove duplicate testcase from ParseLineKeyTest Add initial support for an escape character Add a config parser method which, for now, deals only with escaping the literal backslash character and logs an error message to inform the user of the coming change. The error message includes a properly escaped value for the user. As a result of introducing an escape character('\'): - Warn the user of any unescaped backslashes, as they will not be treated as a literal character in the future - For now, still treat a single backslash as a literal character - Treat two consecutive backslashes as a single properly escaped literal backslash Resolves: First step in polybar#2354 Improve value parsing - Take value arg in as an rvalue reference and move parsed value back - Remove unnecessary if statement - Rename function - Improve error message - Improve function description - Format Fix ParseLineKeyTest test cases Also make config parser method parse_escaped_value private. Remove duplicate testcase from ParseLineKeyTest
0305c15
to
00b60ae
Compare
There was still an issue. I went ahead and just squashed all commits. |
Done! Thanks a lot for all your efforts 😃 |
Thanks a lot for all YOUR efforts. Also, if you don't mind:
|
C++ strings don't have a termination character. If you do str[str.size()], you will access one element to the right of the last one. |
I should've known that, I know the size is stored internally, but no one ever told me that the null termination is not there in C++, I am amazed and embarrassed. |
What type of PR is this? (check all applicable)
Description
Related Issues & Documents
Implements first step of #2354
Documentation (check all applicable)
See Escape characters in configs #2354