ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 2.9.2
    • Affects Version/s: 2.8.2
    • Component/s: None
    • None
    • None
    • Go Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Detailed steps to reproduce the problem?

      The previous implementation of Truncate missed the case where width falls exactly at the end of a multi-byte UTF-8 character.

      F.E

      Truncate("a©bc", 3) // © is encoded as 2 bytes: 0xC2 0xA9
      

      str[:3] ends cleanly after ©, but the old logic checked the last byte (0xA9, pattern 10xxxxxx) and incorrectly treated it as a dangling continuation byte, stepping back past the complete © and returning "a" instead of the correct "a©".

      The same bug affected the expected values in document_test.go and value_test.go, which were written against the incorrect behaviour.

      See PR https://github.com/mongodb/mongo-go-driver/pull/2564

      Definition of done: what must be done to consider the task complete?

      • Fix Truncate in internal/bsoncoreutil to correctly handle the case where width falls exactly on a UTF-8 multi-byte character boundary.

      The exact Go version used, with patch level:

      $ go version

      The exact version of the Go driver used:

      $ go list -m go.mongodb.org/mongo-driver

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      N/A

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      N/A

            Assignee:
            Matt Dale
            Reporter:
            Matt Dale
            Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: