Skip to content

Commit 2cca583

Browse files
Check if the the url is present in the file to avoid a extra replace
1 parent b4f8e20 commit 2cca583

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

flask_apidoc/apidoc.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ def __send_api_file(self, file_name):
9595
with codecs.open(file_name, 'r', 'utf-8') as file:
9696
data = file.read()
9797

98-
# replaces the hard coded url by the
99-
# current url.
98+
# replaces the hard coded url by the current url.
10099
api_project = self.__read_api_project()
101100

102-
new_url = request.url_root.strip('/')
103-
old_url = api_project.get('url', new_url)
104-
data = data.replace(old_url, new_url)
101+
old_url = api_project.get('url')
102+
103+
# replaces the project's url only if it is present in the file.
104+
if old_url:
105+
new_url = request.url_root.strip('/')
106+
data = data.replace(old_url, new_url)
105107

106108
# creates a flask response to send
107109
# the file to the browser

0 commit comments

Comments
 (0)