Wicket
  1. Wicket
  2. WICKET-5263

FilenameWithVersionResourceCachingStrategy breaks silently when the versionPrefix is contained in the original filename

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.9.0
    • Fix Version/s: 6.10.0, 7.0.0
    • Component/s: wicket
    • Labels:
      None

      Description

      If a resource name contains the character used as version prefix then FilenameWithVersionResourceCachingStrategy#undecorateUrl() will split the decorated filename wrongly and the resource response will return 404 (Not found).

        Issue Links

          Activity

          Hide
          Stefan Fussenegger added a comment -

          I've submitted pull request #66 on github according to my comment above.

          Show
          Stefan Fussenegger added a comment - I've submitted pull request #66 on github according to my comment above.
          Hide
          Stefan Fussenegger added a comment -

          Martin Grigorov I wouldn't consider adding a log message a good enough fix for this issue. I think it would be better to patch undecorateUrl(..) to check the validity of the version it tries to strip:

          Current

          // get position of version string
          pos = fullname.lastIndexOf(versionPrefix);
          
          // remove version string if it exists
          if (pos != -1)
          {
            // SNIP
          }
          

          Patched

          // get position of version string
          pos = fullname.lastIndexOf(versionPrefix);
          
          // remove version string if it exists
          if (pos != -1 && isVersion(fullname.substring(pos + versionPrefix.length()))
          {
            // SNIP
          }
          

          The implementation of isVersion(..) isn't obvious as there naturally is one problem: The version depends on the resource and the resource isn't known without properly stripping the version from the URL. I'd therefore suggest to the method getVersionPattern() to IResourceVersion.

          The implementations for all current implementations would be trivial:

          LastModifiedResourceVersion: "[0-9]+" = timestamp in ms
          MessageDigestResourceVersion: "[0-9A-F]+" = hex value (uppercase)
          StaticResourceVersion: Pattern.quote(version)
          CachingResourceVersion and RequestCycleCachedResourceVersion: delegate.getVersionPattern()

          Making this pattern optional (i.e. return null) would retain the current behavior. Sure, it's still prone to errors (e.g. if version prefix is '-' and the resource is foo-1.png -> foo.png) but at least it avoids some (or probably most) errors (e.g. foo-bar1.png).

          Show
          Stefan Fussenegger added a comment - Martin Grigorov I wouldn't consider adding a log message a good enough fix for this issue. I think it would be better to patch undecorateUrl(..) to check the validity of the version it tries to strip: Current // get position of version string pos = fullname.lastIndexOf(versionPrefix); // remove version string if it exists if (pos != -1) { // SNIP } Patched // get position of version string pos = fullname.lastIndexOf(versionPrefix); // remove version string if it exists if (pos != -1 && isVersion(fullname.substring(pos + versionPrefix.length())) { // SNIP } The implementation of isVersion(..) isn't obvious as there naturally is one problem: The version depends on the resource and the resource isn't known without properly stripping the version from the URL. I'd therefore suggest to the method getVersionPattern() to IResourceVersion . The implementations for all current implementations would be trivial: LastModifiedResourceVersion : "[0-9]+" = timestamp in ms MessageDigestResourceVersion : "[0-9A-F]+" = hex value (uppercase) StaticResourceVersion : Pattern.quote(version) CachingResourceVersion and RequestCycleCachedResourceVersion : delegate.getVersionPattern() Making this pattern optional (i.e. return null) would retain the current behavior. Sure, it's still prone to errors (e.g. if version prefix is '-' and the resource is foo-1.png -> foo.png) but at least it avoids some (or probably most) errors (e.g. foo-bar1.png).

            People

            • Assignee:
              Martin Grigorov
              Reporter:
              Martin Grigorov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development