Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "file:///" as hyperlink #508

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions zerver/lib/bugdown/__init__.py
Expand Up @@ -634,7 +634,6 @@ def sanitize_url(url):
except ValueError:
# Bad url - so bad it couldn't be parsed.
return ''

# If there is no scheme or netloc and there is a '@' in the path,
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should remove this whitespace change from the commit.

# treat it as a mailto: and set the appropriate scheme
if scheme == '' and netloc == '' and '@' in path:
Expand All @@ -651,7 +650,7 @@ def sanitize_url(url):
if not scheme:
return sanitize_url('http://' + url)

locless_schemes = ['mailto', 'news']
locless_schemes = ['mailto', 'news', 'file']
if netloc == '' and scheme not in locless_schemes:
# This fails regardless of anything else.
# Return immediately to save additional proccessing
Expand All @@ -661,7 +660,7 @@ def sanitize_url(url):
# appears to have a netloc. Additionally there are plenty of other
# schemes that do weird things like launch external programs. To be
# on the safe side, we whitelist the scheme.
if scheme not in ('http', 'https', 'ftp', 'mailto'):
if scheme not in ('http', 'https', 'ftp', 'mailto', 'file'):
return None

# Upstream code scans path, parameters, and query for colon characters
Expand Down Expand Up @@ -940,12 +939,13 @@ def extendMarkdown(self, md, md_globals):
%s # zero-to-6 sets of paired parens
)?) # Path is optional
| (?:[\w.-]+\@[\w.-]+\.[\w]+) # Email is separate, since it can't have a path
%s
)
(?= # URL must be followed by (not included in group)
[!:;\?\),\.\'\"\>]* # Optional punctuation characters
(?:\Z|\s) # followed by whitespace or end of string
)
""" % (tlds, nested_paren_chunk)
""" % (tlds, nested_paren_chunk, r"| (?:file://(/[^/ ]*)+/?)" if settings.ENABLE_FILE_LINKS else r"")
md.inlinePatterns.add('autolink', AutoLink(link_regex), '>link')

md.preprocessors.add('hanging_ulists',
Expand Down
2 changes: 1 addition & 1 deletion zerver/models.py
Expand Up @@ -999,7 +999,7 @@ def content_has_image(content):

@staticmethod
def content_has_link(content):
return 'http://' in content or 'https://' in content or '/user_uploads' in content
return 'http://' in content or 'https://' in content or '/user_uploads' in content or 'file:///' in content
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm probably this or case should be conditional on settings.ENABLE_FILE_LINKS as well, right?


def update_calculated_fields(self):
# TODO: rendered_content could also be considered a calculated field
Expand Down
1 change: 1 addition & 0 deletions zproject/settings.py
Expand Up @@ -159,6 +159,7 @@ def get_secret(key):
'REMOTE_POSTGRES_SSLMODE': '',
'GOOGLE_CLIENT_ID': '',
'DBX_APNS_CERT_FILE': None,
'ENABLE_FILE_LINKS' : False,
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add a patch to zproject/local_settings_template.py documenting the feature and providing a clear place to set this new setting.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, looks like you did this one.

}

for setting_name, setting_val in DEFAULT_SETTINGS.iteritems():
Expand Down