Skip to content

Commit e3f8803

Browse files
committed
Fix a bug if there is only one slash
1 parent deeeeab commit e3f8803

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

cmd2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,8 +2341,10 @@ def _transform_transcript_expected(self, s):
23412341
# turn through the loop
23422342
start = second_slash_pos + 1
23432343
else:
2344-
# no closing slash, treat it all as plain text
2345-
regex += re.escape(s[start:])
2344+
# No closing slash, we have to add the first slash,
2345+
# and the rest of the text
2346+
regex += re.escape(s[start-1:])
2347+
break
23462348
return regex
23472349

23482350
def _escaped_find(self, regex, s, start, in_regex):

tests/test_transcript.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,18 @@ def test_transcript(request, capsys, filename, feedback_to_output):
310310

311311
@pytest.mark.parametrize('expected, transformed', [
312312
( 'text with no slashes', 'text\ with\ no\ slashes' ),
313+
# stuff with just one slash
314+
( 'use 2/3 cup', 'use\ 2\/3\ cup' ),
315+
( '/tmp is nice', '\/tmp\ is\ nice'),
316+
( 'slash at end/', 'slash\ at\ end\/'),
317+
# regexes
313318
( 'specials .*', 'specials\ \.\*' ),
314319
( '/.*/', '.*' ),
315-
( 'use 2\/3 cup', 'use\ 2\/3\ cup' ),
316320
( 'specials ^ and + /[0-9]+/', 'specials\ \^\ and\ \+\ [0-9]+' ),
317-
( '/a{6}/ but not a{6} with /.*?/ more', 'a{6}\ but\ not\ a\{6\}\ with\ .*?\ more' ),
321+
( '/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}\ but\ not\ \/a\{6\}\ with\ .*?\ more' ),
318322
( 'not this slash\/ or this one\/', 'not\ this\ slash\\/\ or\ this\ one\\/' ),
319323
( 'not \/, use /\|?/, not \/', 'not\ \\/\,\ use\ \|?\,\ not\ \\/' ),
320-
# inception: we have a slashes in our regex: backslashed on input, bare on output
324+
# inception: slashes in our regex. backslashed on input, bare on output
321325
( 'not \/, use /\/?/, not \/', 'not\ \\/\,\ use\ /?\,\ not\ \\/' ),
322326
( 'the /\/?/ more /.*/ stuff', 'the\ /?\ more\ .*\ stuff' ),
323327
])

0 commit comments

Comments
 (0)