Skip to content

Commit 657196d

Browse files
authored
Merge pull request galaxyproject#22286 from mvdbeek/fix-toolshed-imagine-url-encoding
[26.0] Fix toolshed static image url encoding
2 parents 7cbe36c + 4a68685 commit 657196d

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

lib/galaxy/tool_shed/util/shed_util_common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import re
3+
from urllib.parse import quote
34

45
from galaxy import util
56
from galaxy.tool_shed.util import repository_util
@@ -149,7 +150,10 @@ def set_image_paths(app, text, encoded_repository_id=None, tool_shed_repository=
149150
# We're in the tool shed.
150151
route_to_images = f"/repository/static/images/{encoded_repository_id}"
151152
elif tool_shed_repository and tool_id and tool_version:
152-
route_to_images = f"shed_tool_static/{tool_shed_repository.tool_shed}/{tool_shed_repository.owner}/{tool_shed_repository.name}/{tool_id}/{tool_version}"
153+
route_to_images = quote(
154+
f"shed_tool_static/{tool_shed_repository.tool_shed}/{tool_shed_repository.owner}/{tool_shed_repository.name}/{tool_id}/{tool_version}",
155+
safe="/",
156+
)
153157
else:
154158
raise Exception(
155159
"encoded_repository_id or tool_shed_repository and tool_id and tool_version must be provided"

lib/galaxy/webapps/galaxy/controllers/shed_tool_static.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import os
33

44
from galaxy import web
5-
from galaxy.exceptions import RequestParameterInvalidException
5+
from galaxy.exceptions import (
6+
ObjectNotFound,
7+
RequestParameterInvalidException,
8+
)
69
from galaxy.util.path import (
710
join,
811
safe_contains,
@@ -34,6 +37,8 @@ def index(self, trans, shed, owner, repo, tool, version, image_file, **kwargs):
3437
"""
3538
guid = "/".join((shed, "repos", owner, repo, tool, version))
3639
tool = trans.app.toolbox.get_tool(guid)
40+
if tool is None:
41+
raise ObjectNotFound(f"Could not find tool with guid '{guid}'.")
3742
repo_path = os.path.abspath(tool._repository_dir)
3843
found_path = None
3944

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from types import SimpleNamespace
2+
3+
from galaxy.tool_shed.util.shed_util_common import set_image_paths
4+
5+
6+
def test_set_image_paths_encodes_special_characters_in_tool_id():
7+
tool_shed_repository = SimpleNamespace(
8+
tool_shed="toolshed.g2.bx.psu.edu",
9+
owner="devteam",
10+
name="emboss_5",
11+
)
12+
text = ".. image:: static/images/isochore.png"
13+
result = set_image_paths(
14+
app=None,
15+
text=text,
16+
tool_shed_repository=tool_shed_repository,
17+
tool_id="EMBOSS: isochore47",
18+
tool_version="5.0.0.1",
19+
)
20+
assert "EMBOSS%3A%20isochore47" in result
21+
assert "EMBOSS: isochore47" not in result
22+
23+
24+
def test_set_image_paths_preserves_slashes_in_route():
25+
tool_shed_repository = SimpleNamespace(
26+
tool_shed="toolshed.g2.bx.psu.edu",
27+
owner="devteam",
28+
name="emboss_5",
29+
)
30+
text = ".. image:: isochore.png"
31+
result = set_image_paths(
32+
app=None,
33+
text=text,
34+
tool_shed_repository=tool_shed_repository,
35+
tool_id="isochore",
36+
tool_version="5.0.0",
37+
)
38+
assert "shed_tool_static/toolshed.g2.bx.psu.edu/devteam/emboss_5/isochore/5.0.0/" in result
39+
40+
41+
def test_set_image_paths_does_not_modify_http_urls():
42+
tool_shed_repository = SimpleNamespace(
43+
tool_shed="toolshed.g2.bx.psu.edu",
44+
owner="devteam",
45+
name="emboss_5",
46+
)
47+
text = ".. image:: https://example.com/image.png"
48+
result = set_image_paths(
49+
app=None,
50+
text=text,
51+
tool_shed_repository=tool_shed_repository,
52+
tool_id="mytool",
53+
tool_version="1.0",
54+
)
55+
assert ".. image:: https://example.com/image.png" in result
56+
assert "shed_tool_static" not in result

0 commit comments

Comments
 (0)