Skip to content

Commit 208c264

Browse files
authored
Fix failure to properly escape & (#46116)
* Fix failure to properly encode & * Use html escape
1 parent aee2a77 commit 208c264

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

eng/pipelines/scripts/generate_overview_from_readme.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# will be written to overview file. If there is a readme, its contents will be added after that.
1616

1717
import argparse
18+
import html
1819
from bs4 import BeautifulSoup
1920
import pdb
2021
import markdown2
@@ -43,12 +44,17 @@ def generate_overview(readme_file, version, overview_file_path):
4344
if (readme_exists):
4445
with open(readme_file, 'r', encoding='utf-8') as f:
4546
raw_readme_content_lines = f.readlines()
46-
47+
48+
# Replace all instances of & with & in the raw readme content
49+
escaped_readme_content_lines = []
50+
for line in raw_readme_content_lines:
51+
escaped_readme_content_lines.append(html.escape(line, quote=True))
52+
4753
# Before passing the README contents to markdown2 clean out the codesnippet tags on the java code fences.
4854
# Clean ```java com.azure.core.aCodeSnippetTag to ```java, without doing this markdown2 won't properly process
49-
# the contents of the code fence.
55+
# the contents of the code fence.
5056
cleaned_readme_content_lines = []
51-
for line in raw_readme_content_lines:
57+
for line in escaped_readme_content_lines:
5258
cleaned_readme_content_lines.append(re.sub(pattern="``` *java +[a-zA-Z0-9.#\-_]*", repl="```java", string=line, flags=re.UNICODE))
5359

5460
readme_content = ''.join(cleaned_readme_content_lines)
@@ -107,4 +113,4 @@ def main():
107113
raise ValueError('{} is not a readmefile. The --readme-file argument must be a readme.md file.'.format(args.readme_file))
108114

109115
if __name__ == '__main__':
110-
main()
116+
main()

0 commit comments

Comments
 (0)