Edgewall Software
Modify

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)

t5704-r6397-imagemacro_externals-a.diff (2.1 KB ) - added by osimons 17 years ago.
Patch that makes image macro handle external urls better regardless of form.
t5704-r6400-imagemacro_externals-a.diff (3.4 KB ) - added by osimons 17 years ago.
Adding some tests for new functionality - and a fix for a markup issue it revealed.

Download all attachments as: .zip

Change History (9)

comment:1 by hyuga <hyugaricdeau@…>, 17 years ago

Milestone: 0.11
Version: devel0.11b1

This issue still exists in 0.11b1. The problem begins at line 366:

366             parts = filespec.split(':')
367             url = raw_url = None
368             attachment = None
369             if len(parts) == 3:                 # realm:id:attachment-filename
370                 realm, id, filename = parts
371                 attachment = Resource(realm, id).child('attachment', filename)

A URL containing a port number is split into three parts, and Trac parses this as a realm, id, and filename.

by osimons, 17 years ago

Patch that makes image macro handle external urls better regardless of form.

comment:2 by osimons, 17 years ago

Owner: changed from Christian Boos to osimons

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.

comment:3 by Christian Boos, 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).

in reply to:  3 comment:4 by osimons, 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 Christian Boos, 17 years ago

I don't know… it works fine for me, e.g.

  • trac/wiki/tests/macros.py

     
    55
    66IMAGE_MACRO_TEST_CASES=u"""
    77============================== source: Image, no other arguments
    8 [[Image(source:test.png)]]
     8[[Image(sourc:test.png)]]
    99------------------------------
    1010<p>
    1111<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>
     
    1313------------------------------
    1414[[Image(...)]]
    1515============================== source: Image, nolink
    16 [[Image(source:test.png, nolink)]]
     16[[Image(source:text.png, nolink)]]
    1717------------------------------
    1818<p>
    1919<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 osimons, 17 years ago

Adding some tests for new functionality - and a fix for a markup issue it revealed.

comment:6 by osimons, 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 osimons, 17 years ago

Resolution: fixed
Status: newclosed

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.)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain osimons.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from osimons to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.