changeset 46385:aaff3bc75306

minirst: respect escaping in definition list key If we start adding `:` in command names… we need minirst to not choke on them. Differential Revision: https://phab.mercurial-scm.org/D9869
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 25 Jan 2021 23:07:56 +0100
parents 7bb31c367847
children d481f30ea8e3
files mercurial/minirst.py tests/test-minirst.py tests/test-minirst.py.out
diffstat 3 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/minirst.py	Tue Jan 26 00:45:40 2021 +0100
+++ b/mercurial/minirst.py	Mon Jan 25 23:07:56 2021 +0100
@@ -158,7 +158,7 @@
 _optionre = re.compile(
     br'^(-([a-zA-Z0-9]), )?(--[a-z0-9-]+)' br'((.*)  +)(.*)$'
 )
-_fieldre = re.compile(br':(?![: ])([^:]*)(?<! ):[ ]+(.*)')
+_fieldre = re.compile(br':(?![: ])((?:\:|[^:])*)(?<! ):[ ]+(.*)')
 _definitionre = re.compile(br'[^ ]')
 _tablere = re.compile(br'(=+\s+)*=+')
 
@@ -229,7 +229,7 @@
             m = _fieldre.match(blocks[j][b'lines'][0])
             key, rest = m.groups()
             blocks[j][b'lines'][0] = rest
-            blocks[j][b'key'] = key
+            blocks[j][b'key'] = key.replace(br'\:', b':')
             j += 1
 
         i = j + 1
--- a/tests/test-minirst.py	Tue Jan 26 00:45:40 2021 +0100
+++ b/tests/test-minirst.py	Mon Jan 25 23:07:56 2021 +0100
@@ -159,6 +159,8 @@
 :a: First item.
 :ab: Second item. Indentation and wrapping
      is handled automatically.
+:c\:d: a key with colon
+:efg\:\:hh: a key with many colon
 
 Next list:
 
--- a/tests/test-minirst.py.out	Tue Jan 26 00:45:40 2021 +0100
+++ b/tests/test-minirst.py.out	Mon Jan 25 23:07:56 2021 +0100
@@ -439,6 +439,8 @@
 a             First item.
 ab            Second item. Indentation and wrapping is
               handled automatically.
+c:d           a key with colon
+efg::hh       a key with many colon
 
 Next list:
 
@@ -456,6 +458,9 @@
               wrapping is
               handled
               automatically.
+c:d           a key with colon
+efg::hh       a key with many
+              colon
 
 Next list:
 
@@ -476,6 +481,10 @@
  <dd>First item.
  <dt>ab
  <dd>Second item. Indentation and wrapping is handled automatically.
+ <dt>c:d
+ <dd>a key with colon
+ <dt>efg::hh
+ <dd>a key with many colon
 </dl>
 <p>
 Next list: