-
Notifications
You must be signed in to change notification settings - Fork 10
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
Allow relative urls #47
Open
Goury
wants to merge
3
commits into
ellmetha:main
Choose a base branch
from
Goury:allow-relative-urls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import re | ||
from collections import defaultdict | ||
|
||
from django.core.validators import URLValidator | ||
|
||
from precise_bbcode.bbcode.regexes import url_re | ||
from precise_bbcode.conf import settings as bbcode_settings | ||
from precise_bbcode.core.utils import replace | ||
|
@@ -402,8 +404,19 @@ def _render_textual_content(self, data, replace_specialchars, replace_links, rep | |
if replace_links: | ||
def linkrepl(match): | ||
url = match.group(0) | ||
href = url if '://' in url else 'http://' + url | ||
return '<a href="{0}">{1}</a>'.format(href, url) | ||
for xss in bbcode_settings.URL_XSS_FILTER: | ||
if xss in url: | ||
return url | ||
Comment on lines
+407
to
+409
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is duplicated in three places. Could we define it in a shared method to avoid the duplication (eg. in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On it |
||
if url[:2] == '//': | ||
return url | ||
if '://' in url: | ||
v = URLValidator() | ||
try: | ||
v(url) | ||
except ValidationError: | ||
return url | ||
|
||
return '<a href="{0}">{1}</a>'.format(url, url) | ||
data = re.sub(url_re, linkrepl, data) | ||
|
||
if replace_smilies: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this logic? This is going to introduce a change in behavior and I don't think this is necessary in order to allow relative URLs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¯\_(ツ)_/¯
Just felt this way.
I believe you're right, let's not change it too too much.