Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-23506

Comments are ordered by date of type String instead of type date

    XMLWordPrintable

Details

    • Integration
    • Unknown
    • N/A
    • N/A

    Description

      The issue come from `commentsinline.vm` and a part of the code introduced by XWIKI-22978 .

      • Cause :
      ## Build a map on the form Date -> List<Comment object>
      ## We also keep the set of keys when we have multiple comments at same date just to order them later (it should be a
      ## very rare case but let's ensure we keep a deterministic order)
      #set ($commentMap = $collectiontool.getSortedMap())
      #set ($keysWithMultipleComments = $collectiontool.getSet())
      #foreach ($comment in $comments)
        #set ($key = $comment.date)
        #if ($commentMap.containsKey($key))
          #set ($discard = $commentMap.get($key).add($comment))
          #set ($discard = $keysWithMultipleComments.add($key))
        #else
          #set ($discard = $commentMap.put($key, [$comment]))
        #end
      #end
      

      The list is ordered by key and the line `#set ($key = $comment.date)` will set the list to be ordered by date.
      The issue here is `$comment.data` get a date as String (example : “23/11/2017 14:25:44”), and then the sortedMap see a String and will order as text.

      • How to reproduce

      1. Create multiple comments on the same document
      2. Update the last comment date to be a day be a day before a previous comment, but also add one to the year, so the comment is still the last one (workd also with month)
      Result : The modified comment, is ordered by the day and become the first comment.

      Expected : As the year is higher, it must be the last one.

      Attachments

        Issue Links

          Activity

            People

              surli Simon Urli
              fveron Florian Véron
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: