Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6289

Autolinking adds onclick attribute to <img> tags

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 7.4.0, 8.0.0-M2, 6.25.0, 1.5.17
    • 7.6.0, 8.0.0-M3
    • None
    • None

    Description

      When the autolinker can't find the target of a src or href attribute, it falls back to a default autocomponent, that supposedly leaves the tag unchanged. Quoting AutolinkResolver:

      if (autoComponent == null)
      {
      	// resolving didn't have the desired result or there was no delegate
      	// found; fallback on the default resolving which is a simple
      	// component that leaves the tag unchanged
      	autoComponent = new AutolinkExternalLink(componentId, pathInfo.reference);
      }
      

      ...except that AutolinkExternalLink is an ExternalLink which is an AbstractLink which does change the original tag. Namely, when applied to something that is not <a> it adds an onclick attribute. This leads to something like the following:

      <img src="does-not-exist.png" onclick="window.location.href=&#039;does-not-exist.png&#039;;return false;"/>
      

      ...which is clearly nonsensical. This can happen when the referenced image is not in the classpath - it could either be missing, or it could be in the webapp root somewhere, which can be the case for some legacy applications. (This is how I came across this.)

      A simple fix appears to be to use a plain WebMarkupContainer in place of this particular AutolinkExternalLink. All tests pass when I do that.

      This affects all versions from 1.5 on upward. I'll prepare a pull request.

      Attachments

        Issue Links

          Activity

            People

              cmenzel Carl-Eric Menzel
              cmenzel Carl-Eric Menzel
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: