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

feat: add a test for placeholder escaping #9

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

Conversation

acuteenvy
Copy link
Member

No description provided.

Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

What about testing if the placeholder brackets is not rendered in the scaped curly brackets run too? Maybe in mixed examples it can render the escaped curly brackets correctly but also, erroneously, render the not escaped placeholder brackets.

@test "REQUIRED: supports escaping the placeholder syntax" {
run $PATH_TO_TLDR_CLIENT docker inspect
[[ $status -eq 0 ]]
[[ "$output" = *"{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}"* ]]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[[ "$output" = *"{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}"* ]]
[[ "$output" = *"'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container`"* ]]

Copy link
Member

@SethFalco SethFalco Mar 18, 2024

Choose a reason for hiding this comment

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

I don't think that suggestion adds much value, meanwhile it does add potential complexity with handling different styles, colors, or ANSI codes between arguments in different clients.

I think we should stick to the original proposal.

Reference: #9 (comment)

Copy link
Member

@vitorhcl vitorhcl Mar 19, 2024

Choose a reason for hiding this comment

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

Maybe split this into the past version and this suggestion, making the latter optional, with NO_COLOR set to true? I do think that the backslashes can confuse clients.

Well, the other test already tests the placeholder between the escaped curly brackets, right? So what's the point here?

Copy link
Member

Choose a reason for hiding this comment

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

Which test are you referring to there?

I don't think we're testing escaped curly braces yet. It was a relatively recent addition to the spec compared to when I wrote these tests.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was talking about the other line of this test

Copy link
Member

Choose a reason for hiding this comment

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

These two tests are different.

  1. One tests that escaped curly braces are rendered correctly. \{\{arg\}\}{{arg}}
  2. One ensures that double backslash (normally interpreted as escaped backslashes) are rendered correctly. It does not test escaped curly braces. \\arg\\arg

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I'm not saying they are equivalent. But the double backslash test, want it or not, also tests the rendering of the placeholders, so it should theoretically suffer from the same problems you mentioned

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what you're trying to say. These are both handling entirely different scenarios. It's possible to craft input that could pass or fail both, but this is about how escapes are handled, which any clients could handle one escape correctly but not the other.

Copy link
Member

Choose a reason for hiding this comment

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

See Microsoft documentation:

mount -o anon \ServerIP\ShareName Z:

The original Markdown is:

mount \{{computer_name}}{{share_name}} {{Z:}}

If I'm getting it right, it should be rendered as:

mount \{{computer_name}}{{share_name}} {{Z:}}

Yeah, they are different, because the mount page doesn't test escaped placeholders, but it does test text between the placeholders, so it could theorically suffer from the problems you mentioned such as ANSI codes.

I hope you understand me now 😅

Copy link
Member

@SethFalco SethFalco Mar 19, 2024

Choose a reason for hiding this comment

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

Ahh, I'm following now! Yeah, the second test is actually written wrong then in that case.

Don't include curly braces in tests, clients are free to remove/replace them.

That really should say placeholder syntax, escaped curly braces are fine. Clients are free to render it as \\{{computer_name}}\{{share_name}} or \\computer_name\share_name, usually if a client does the latter they use colors/styles to signify the args.

It should only check what it wants to test, so the \\ part, or we could check for multiple tokens like \\ and computer_name, but the assertions should not include the {{.

@vitorhcl vitorhcl requested a review from SethFalco March 15, 2024 20:19
@SethFalco
Copy link
Member

Thanks for pinging me, I forgot to watch the repo after transferring it. 😅
I'll review this on Monday.

[[ "$output" = *"{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}"* ]]
run $PATH_TO_TLDR_CLIENT --platform windows mount
[[ $status -eq 0 ]]
[[ "$output" = *"\\computer_name\share_name"* ]]
Copy link
Member

@SethFalco SethFalco Mar 18, 2024

Choose a reason for hiding this comment

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

This test and the associated specifications are odd to me. If we are using CommonMark, then \\ should become a single backslash.

The page should have \\\\{computer_name}\\{share_name}, which would render out to \\{computer_name}\{share_name}, right?

With the specifications as they are written, I don't think the specifications make sense. This does look to me like it tests what the specifications intended, though.

@test "REQUIRED: supports escaping the placeholder syntax" {
run $PATH_TO_TLDR_CLIENT docker inspect
[[ $status -eq 0 ]]
[[ "$output" = *"{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}"* ]]
Copy link
Member

@SethFalco SethFalco Mar 18, 2024

Choose a reason for hiding this comment

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

I don't think that suggestion adds much value, meanwhile it does add potential complexity with handling different styles, colors, or ANSI codes between arguments in different clients.

I think we should stick to the original proposal.

Reference: #9 (comment)

@acuteenvy
Copy link
Member Author

If we are using CommonMark, then \\ should become a single backslash.

The page should have \\\\{computer_name}\\{share_name}, which would render out to \\{computer_name}\{share_name}, right?

The backslashes are inside a code block, so they would be treated literally even by a CommonMark parser.
https://spec.commonmark.org/0.31.2/#example-338

Note that backslash escapes do not work in code spans. All backslashes are treated literally


The current client specification doesn't strictly follow CommonMark. Single braces can't be escaped - \{\{ is rendered as {{, whereas \{{ is treated literally. This creates issues, because there are special cases where escaping a single brace would be useful. However, the client spec PR for escaping was merged without accounting for these cases to prevent doubling all backslashes in Windows paths.

I don't think the specifications make sense.

The only other way is to release a specification which states that every brace can be escaped, and all backslashes must be. The problem with that is, most clients will display double backslashes everywhere for a while.


Clients are free to render it as \\{{computer_name}}\{{share_name}} or \\computer_name\share_name, usually if a client does the latter they use colors/styles to signify the args.

https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#page-structure

Clients MAY highlight the placeholders and MUST remove the surrounding curly braces.

If a client removes backlashes and doesn't remove braces that mark the placeholder, the user won't know which braces are part of the command.

@SethFalco
Copy link
Member

SethFalco commented Mar 21, 2024

The backslashes are inside a code block, so they would be treated literally even by a CommonMark parser.

Ahh, you're right. I forgot they were in inline code. It seems I made the same mistake during the initial discussion for that revision to spec, too. ^-^'

If a client removes backlashes and doesn't remove braces that mark the placeholder, the user won't know which braces are part of the command.

Understood, I misinterpreted the spec, thank you for clarifying this. I would still expect us to use the approach proposed (checking "token" at a time) to avoid issues with formatting, ANSI codes, etc. However, indeed we should disregard my comments regarding curly braces being optional. In a separate commit, I will also remove the comment I've left in the test file about this.


In that case, this all looks good to me. Thanks for adding the test, and being patient with me and my misguided review. 😅

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