Bug 4569 - Incorrect Escapes in Templates/Styles
Summary: Incorrect Escapes in Templates/Styles
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: templater (show other bugs)
Version: 3.3.2
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-16 17:20 UTC by Kevin O. Grover
Modified: 2015-05-15 01:00 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments
Step 1 - Makes test repository (Bash) (233 bytes, application/octet-stream)
2015-03-16 17:24 UTC, Kevin O. Grover
Details
Step 2 - Make test templates/styles. (223 bytes, application/octet-stream)
2015-03-16 17:24 UTC, Kevin O. Grover
Details
Step 3 - Test templates/styles. (158 bytes, application/octet-stream)
2015-03-16 17:25 UTC, Kevin O. Grover
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin O. Grover 2015-03-16 17:20 UTC

    
Comment 1 Matt Mackall 2015-03-16 17:21 UTC
No description.
Comment 2 Kevin O. Grover 2015-03-16 17:24 UTC
Created attachment 1817 [details]
Step 1 - Makes test repository (Bash)
Comment 3 Kevin O. Grover 2015-03-16 17:24 UTC
Created attachment 1818 [details]
Step 2 - Make test templates/styles.
Comment 4 Kevin O. Grover 2015-03-16 17:25 UTC
Created attachment 1819 [details]
Step 3 - Test templates/styles.
Comment 5 Kevin O. Grover 2015-03-16 17:25 UTC
This was tested under under Debian 7 and Ubuntu 14.04 (running hg 3.3 on Ubuntu) and manually on Windows 7 running hg 3.3.  I've also switched the style to use " and \", but it does not seem to make any difference.

Summary.   If I have these styles: works.style, broke.style

## works.style
changeset = '{files}'
file = '    "//path/to/dir/{file|urlescape}"\n'


## broke.style
changeset = '{files}'
file = '    "\\\\path\\to\\dir\\{file|urlescape}"\n'

## This seems OK

$ hg -R repo log --style=./works.style
    "//path/to/dir/afile.txt"
    "//path/to/dir/anotherfile.txt"
    "//path/to/dir/with%20space.txt"

## This is not what I expect

$ hg -R repo log --style=./broke.style
    "\path	o\dir{file|urlescape}"
    "\path	o\dir{file|urlescape}"
    "\path	o\dir{file|urlescape}"

I would expect the \\ to take precedence over the others, but \t and \{ seems to take precedence  - I would surmise that all standard escape codes take precedence.

To run the scripts

chmod +x mkrepo mktemplates test_templates
./mkrepo
./mktemplates
./test_templates
Comment 6 bloops 2015-03-26 08:34 UTC
This seems to be a duplicate of http://bz.selenic.com/show_bug.cgi?id=4290 which was unfortunately automatically archived without actual fix.
Comment 7 HG Bot 2015-05-07 15:00 UTC
Fixed by http://selenic.com/repo/hg/rev/890845af1ac2
Yuya Nishihara <yuya@tcha.org>
templater: strictly parse leading backslashes of '{' (issue4569) (BC)

Because double backslashes are processed as a string escape sequence, '\\{'
should start the template syntax. On the other hand, r'' disables any sort
of \-escapes, so r'\{' can go either way, never start the template syntax
or always start it. I simply chose the latter, which means r'\{' is the same
as '\\{'.

(please test the fix)
Comment 8 Bugzilla 2015-05-15 01:00 UTC
Bug was set to TESTING for 7 days, resolving