Skip to content

Commit

Permalink
[jarun#642] fixed URL validation
Browse files Browse the repository at this point in the history
  • Loading branch information
LeXofLeviafan committed Dec 13, 2022
1 parent 304a0a1 commit eba8fca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bukuserver/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HomeForm(SearchBookmarksForm):


class BookmarkForm(FlaskForm):
url = wtforms.StringField('Url', name='link', validators=[wtforms.validators.DataRequired()])
url = wtforms.StringField('Url', name='link', validators=[wtforms.validators.InputRequired()])
title = wtforms.StringField()
tags = wtforms.StringField()
description = wtforms.TextAreaField()
Expand Down
2 changes: 2 additions & 0 deletions bukuserver/templates/bukuserver/lib.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
<script>{
const TARGET = {{ (' target="_blank"' if config.get('BUKUSERVER_OPEN_IN_NEW_TAB', False) else '') | tojson }};
$(`{{prefix}} td:nth-child(2)`).html((_, s) => s.trim().replaceAll('\n', '<br/>'));
{% if session.pop('netloc', None) %}
$(`{{prefix}} td:contains({{ _gettext('Url') | tojson }}) + td`).html((_, s) => `<a href="${s.replaceAll('"', '&quot;')}"${TARGET}>${s}</a>`);
{% endif %}
}</script>
{% endmacro %}

Expand Down
6 changes: 4 additions & 2 deletions bukuserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _list_entry(self, context: Any, model: Namespace, name: str) -> Markup:
)
tag_text_markup = "".join(tag_text)
description = model.description and br_tag.join(map(escape, model.description.split('\n')))
if not netloc and not parsed_url.scheme:
if not netloc:
return Markup(br_tag.join([escape(model.title), escape(model.url), tag_text_markup, description]))
res = []
if not current_app.config.get("BUKUSERVER_DISABLE_FAVICON", False) and netloc:
Expand Down Expand Up @@ -189,7 +189,7 @@ def create_model(self, form):
form.populate_obj(model)
vars(model).pop("id")
self._on_model_change(form, model, True)
if not model.url.strip():
if not model.url:
raise ValueError(f"url invalid: {model.url}")
kwargs = {'url': model.url, 'fetch': model.fetch}
if model.tags.strip():
Expand Down Expand Up @@ -282,6 +282,8 @@ def get_one(self, id):
setattr(bm_sns, field.name.lower(), value.replace(',', ', '))
else:
setattr(bm_sns, field.name.lower(), bookmark[field.value])
if field == BookmarkField.URL:
session['netloc'] = urlparse(bookmark[field.value]).netloc
return bm_sns

def get_pk_value(self, model):
Expand Down

0 comments on commit eba8fca

Please sign in to comment.