Skip to content

Commit

Permalink
More robustly escape input character to cope with special regexp inpu…
Browse files Browse the repository at this point in the history
…ts like brackets
  • Loading branch information
srebhan authored and PierreMarchand20 committed Jun 10, 2023
1 parent eb5a913 commit 54a30fa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 2 additions & 5 deletions asciinema_automation/instruction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import random
import re
import time

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -55,11 +56,7 @@ def run(self, script):
self.receive_value = self.send_value

# Check for special character
if "\\" in self.send_value:
self.receive_value = [
character if character != "\\" else character + "\\"
for character in list(self.send_value)
]
self.receive_value = [re.escape(c) for c in list(self.send_value)]

# Write intruction
for send_character, receive_character in zip(
Expand Down
2 changes: 2 additions & 0 deletions examples/special_character.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#$ sendcharacter #
This is a test with URL (https://github.com)
3 changes: 3 additions & 0 deletions tests/reference_output/special_character.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[?2004h$ #This is a test with URL (https://github.com)
[?2004l[?2004h$ [?2004l
exit
Expand Down

0 comments on commit 54a30fa

Please sign in to comment.