From 5efc6852206dbbeb696d9938bca2cfa443f3dd45 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 2 Aug 2020 18:17:51 +0100 Subject: [PATCH] Avoid adding quites within markup --- content.py | 19 +++++++++++-------- tests.py | 4 ++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/content.py b/content.py index bf82ce03..56a76892 100644 --- a/content.py +++ b/content.py @@ -27,17 +27,20 @@ def htmlReplaceQuoteMarks(content: str) -> str: newContent = '' openQuote = True - noOfSections = len(sections) - ctr = 0 - for s in sections: - newContent += s - if ctr < noOfSections - 1: + markup = False + for ch in content: + currChar = ch + if ch == '<': + markup = True + elif ch == '>': + markup = False + elif ch == '"' and not markup: if openQuote: - newContent += '' + currChar = '' else: - newContent += '' + currChar = '' openQuote = not openQuote - ctr += 1 + newContent += currChar return newContent diff --git a/tests.py b/tests.py index e1038c34..5f0e0857 100644 --- a/tests.py +++ b/tests.py @@ -1938,6 +1938,10 @@ def runHtmlReplaceQuoteMarks(): result = htmlReplaceQuoteMarks(testStr) assert result == 'hello' + testStr = '"hello" test html' + result = htmlReplaceQuoteMarks(testStr) + assert result == 'hello test html' + def runAllTests(): print('Running tests...')