Skip to content
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 for escape syntax to enable literal placeholders #11904

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

droidmonkey
Copy link
Member

Testing strategy

Added a test case, all existing ones pass, this is a minimal change that would not break existing placeholder syntax.

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

@droidmonkey droidmonkey added the pr: bugfix Pull request that fixes a bug label Mar 16, 2025
@droidmonkey droidmonkey added this to the v2.7.11 milestone Mar 16, 2025
@droidmonkey droidmonkey requested a review from phoerious March 16, 2025 12:06
Copy link

codecov bot commented Mar 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.89%. Comparing base (37ddbb3) to head (1b1c2b0).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #11904      +/-   ##
===========================================
- Coverage    63.92%   63.89%   -0.03%     
===========================================
  Files          369      369              
  Lines        38920    38925       +5     
===========================================
- Hits         24878    24871       -7     
- Misses       14042    14054      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -49,6 +49,8 @@ This section contains full details on advanced features available in KeePassXC.
|{DB_DIR} |Absolute directory path of database file
|===

NOTE: You can insert literal placeholder strings by escaping the beginning and ending curly braces. For example, to insert the string `{USERNAME}`, you would type `++\{USERNAME\}++`.
Copy link
Member

Choose a reason for hiding this comment

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

What's the ++ for?

Copy link
Member Author

@droidmonkey droidmonkey Mar 16, 2025

Choose a reason for hiding this comment

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

It allows printing the \{ and \} in the code block. Without that it doesn't print

Copy link
Member

@phoerious phoerious Mar 16, 2025

Choose a reason for hiding this comment

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

Sure about that? At least here it seems to work, but maybe that's an ascii doc quirk. \{USERNAME\}

Edit: I see, seems to be needed indeed, though double-\ might work as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Double \ prints a double \ . Quirky

Comment on lines +1062 to +1070
// Short circuit if we have escaped the placeholder brackets
if (str.startsWith("\\{") && str.endsWith("\\}")) {
// Replace the escaped brackets with actuals and move on
auto ret = str;
ret.replace(0, 2, "{");
ret.replace(ret.size() - 2, 2, "}");
return ret;
}

Copy link
Member

Choose a reason for hiding this comment

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

This is a very brittle escaping mechanism. Either we need a proper state machine for parsing the syntax or this should at least be part of the regex, e.g. as negative lookbehinds/lookaheads.

@droidmonkey droidmonkey force-pushed the fix/escape-placeholder branch from e09cf0b to 1b1c2b0 Compare March 30, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: bugfix Pull request that fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

T-REPLACE-RX doesn't work as expected when escaping curly braces
2 participants