Skip to content

Commit

Permalink
Merge pull request #1503 from RogerHaase/1497-url-encode
Browse files Browse the repository at this point in the history
1497 url encode
  • Loading branch information
RogerHaase authored Sep 10, 2023
2 parents b8b82a4 + 96d795a commit a66e30f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/moin/converters/_tests/test_mediawiki_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ def test_table(self, input, output):
('[[File:MyImage.png|arg=http://google.com|caption]]',
'<page><body><p><object alt="caption" xlink:href="wiki.local:MyImage.png?arg=http%253A%252F%252Fgoogle.com&amp;do=get">caption</object></p></body></page>'),
('[[File:Test.png|do=get|arg1=test|arg2=something else]]',
'<page><body><p><object alt="Test.png" xlink:href="wiki.local:Test.png?arg1=test&amp;arg2=something+else&amp;do=get">Test.png</object></p></body></page>'),
'<page><body><p><object alt="Test.png" xlink:href="wiki.local:Test.png?do=get&amp;arg1=test&amp;arg2=something+else">Test.png</object></p></body></page>'),
# The do=xxx part is just to test if do in args is being updated correctly, it's invalid otherwise
('[[File:Test2.png|do=xxx|caption|arg1=test]]',
'<page><body><p><object alt="caption" xlink:href="wiki.local:Test2.png?arg1=test&amp;do=xxx">caption</object></p></body></page>'),
'<page><body><p><object alt="caption" xlink:href="wiki.local:Test2.png?do=xxx&amp;arg1=test">caption</object></p></body></page>'),
("[[File:myimg.png|'Graph showing width |= k for 5 < k < 10']]",
'<page><body><p><object alt="Graph showing width |= k for 5 &lt; k &lt; 10" xlink:href="wiki.local:myimg.png?do=get">Graph showing width |= k for 5 &lt; k &lt; 10</object></p></body></page>'),
("[[File:myimg.png|arg1='longish caption value with |= to test'|arg2=other|test stuff]]",
Expand Down
4 changes: 2 additions & 2 deletions src/moin/converters/html_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from flask import current_app as app
from emeraldtree import ElementTree as ET
from werkzeug.urls import url_encode
from urllib.parse import urlencode

from moin import wikiutil
from moin.i18n import _
Expand Down Expand Up @@ -63,7 +63,7 @@ def mark_item_as_transclusion(elem, href_or_item):
in a span or div and 2 overlay siblings will be created.
"""
if isinstance(href_or_item, Item):
query = url_encode({'do': 'show'}, charset=CHARSET)
query = urlencode({'do': 'show'}, encoding=CHARSET)
href = Iri(scheme='wiki', authority='', path='/' + href_or_item.fqname.fullname, query=query)
else: # isinstance(href_or_item, Iri)
href = href_or_item
Expand Down
5 changes: 3 additions & 2 deletions src/moin/converters/image_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Convert image to <object> tag for the DOM Tree.
"""

from werkzeug.urls import url_encode, url_decode
from werkzeug.urls import url_decode
from urllib.parse import urlencode

from moin.constants.contenttypes import CHARSET
from moin.utils.iri import Iri
Expand Down Expand Up @@ -40,7 +41,7 @@ def __call__(self, rev, contenttype=None, arguments=None):
query_keys.update(url_decode(query.query))
attrib = arguments.keyword

query = url_encode(query_keys, charset=CHARSET)
query = urlencode(query_keys, encoding=CHARSET)

attrib.update({
moin_page.type_: str(self.input_type),
Expand Down
6 changes: 3 additions & 3 deletions src/moin/converters/mediawiki_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import re
from html.entities import name2codepoint

from werkzeug.urls import url_encode
from urllib.parse import urlencode

from moin.constants.contenttypes import CHARSET
from moin.constants.misc import URI_SCHEMES
Expand Down Expand Up @@ -643,7 +643,7 @@ def inline_link_repl(self, stack, link, link_url=None, link_item=None,
parsed_args = self.parse_args(link_args[1:])
query = None
if parsed_args.keyword:
query = url_encode(parsed_args.keyword, charset=CHARSET, sort=True)
query = urlencode(parsed_args.keyword, encoding=CHARSET)
# Take the last of positional parameters as link_text(caption)
if parsed_args.positional:
link_text = parsed_args.positional.pop()
Expand All @@ -662,7 +662,7 @@ def inline_link_repl(self, stack, link, link_url=None, link_item=None,
if 'do' not in args:
# by default, we want the item's get url for transclusion of raw data:
args['do'] = 'get'
query = url_encode(args, charset=CHARSET, sort=True)
query = urlencode(args, encoding=CHARSET)
target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
text = object_item
else:
Expand Down
4 changes: 2 additions & 2 deletions src/moin/converters/moinwiki_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re

from flask import request
from werkzeug.urls import url_encode
from urllib.parse import urlencode

from moin.constants.contenttypes import CHARSET
from moin.constants.misc import URI_SCHEMES
Expand Down Expand Up @@ -855,7 +855,7 @@ def inline_object_repl(self, stack, object, object_url=None, object_item=None,
attrib[html.alt] = object_text
if object_item is not None:
# img tag
query = url_encode(query_keys, charset=CHARSET)
query = urlencode(query_keys, encoding=CHARSET)
# TODO: moin 1.9 needed this for an attached file; move functionality to scripts/migration/moin/import19.py
att = 'attachment:'
if object_item.startswith(att):
Expand Down

0 comments on commit a66e30f

Please sign in to comment.