Opened 17 years ago
Closed 17 years ago
#5704 closed defect (fixed)
Image macro does not understand the port in URL protocol
Reported by: | anonymous | Owned by: | osimons |
---|---|---|---|
Priority: | normal | Milestone: | 0.11 |
Component: | wiki system | Version: | 0.11b1 |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
That url works http://192.168.200.202/icq/76576576576
That does not http://192.168.200.202:8080/icq/76576576576
and returns the following error Error: Macro Image(http://192.168.200.202:8080/icq/9879879798) failed Attachment 'http://192.168.200.202:8080/icq/9879879798' does not exist.
Attachments (2)
Change History (9)
comment:1 by , 17 years ago
Milestone: | → 0.11 |
---|---|
Version: | devel → 0.11b1 |
by , 17 years ago
Attachment: | t5704-r6397-imagemacro_externals-a.diff added |
---|
Patch that makes image macro handle external urls better regardless of form.
comment:2 by , 17 years ago
Owner: | changed from | to
---|
Reviewing the current Image macro code, there are many pitfalls with current way of doing things. Even assuming that there will not be more than max. 3 parts (with port) is not enough. I looked at the new Google Chart api, and they even use ':' inside the query string. The macro just sees the full string, and will have no idea about this.
To make this work consistently regardless of how the url looks, I had to lift it out into its own top-level comparison. Patch for this is attached.
It also adds a server-relative alternative for externals, so that one can write '/images/mypicture.jpg'. This works better for servers that have both http and https access for same content.
Does it work as expected for various urls? Please review.
follow-up: 4 comment:3 by , 17 years ago
Looks good, +1
Also, it would be worth taking this opportunity for extending the [[Image]] unit-tests (source:/trunk/trac/wiki/tests/macros.py).
comment:4 by , 17 years ago
Replying to cboos:
Also, it would be worth taking this opportunity for extending the [[Image]] unit-tests (source:/trunk/trac/wiki/tests/macros.py).
Had a look at them to see how they work, and even when changing existing tests to plainly wrong results I can't get any failures from running them. Do we need some sort of Image macro dummy stub as well? What am I missing?
comment:5 by , 17 years ago
I don't know… it works fine for me, e.g.
-
trac/wiki/tests/macros.py
5 5 6 6 IMAGE_MACRO_TEST_CASES=u""" 7 7 ============================== source: Image, no other arguments 8 [[Image(sourc e:test.png)]]8 [[Image(sourc:test.png)]] 9 9 ------------------------------ 10 10 <p> 11 11 <a style="padding:0; border:none" href="/browser/test.png"><img src="/browser/test.png?format=raw" alt="source:test.png" title="source:test.png" /></a> … … 13 13 ------------------------------ 14 14 [[Image(...)]] 15 15 ============================== source: Image, nolink 16 [[Image(source:te st.png, nolink)]]16 [[Image(source:text.png, nolink)]] 17 17 ------------------------------ 18 18 <p> 19 19 <img src="/browser/test.png?format=raw" alt="source:test.png" title="source:test.png" />
results in:
$ python setup.py test -s trac.wiki.tests.macros.suite running test ... Test source: Image, no other arguments ... FAIL Test source: Image, no other arguments ... ok Test source: Image, nolink ... FAIL Test source: Image, normal args ... ok Test source: Image, size arg ... ok Test source: Image, keyword alignment ... ok Test http: Image, nolink ... ok ====================================================================== FAIL: Test source: Image, no other arguments ---------------------------------------------------------------------- Traceback (most recent call last): File "c:\workspace\src\trac\repos\trunk\trac\wiki\tests\formatter.py", line 155, in test raise AssertionError( # See below for details AssertionError: --------------- expected: ... --------------- actual: ... etc.
by , 17 years ago
Attachment: | t5704-r6400-imagemacro_externals-a.diff added |
---|
Adding some tests for new functionality - and a fix for a markup issue it revealed.
comment:6 by , 17 years ago
Right, got the tests added and working. My mistake as usual… New patch attached.
Anyway, the tests then revealed an isse with the href=""
escaping the Google test url I use so that &
showed as $amp;
.
Chatted with coderanger, and this is the solution we ended up with (I think). Basically remove any double-quotes that can terminate the attribute, and then just mark it as safe. title=
and alt=
is still escaped, of course.
Is this OK? Any better ways of doing it?
comment:7 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in [6413] - also adding server- and project-relative linking to input alternatives.
(Turns out I was over-complicating the issue of quoting and escaping - html escaping of all content seems fine.)
This issue still exists in 0.11b1. The problem begins at line 366:
A URL containing a port number is split into three parts, and Trac parses this as a realm, id, and filename.