Skip to content

split('') and special characters #2518

Closed

Description

@neumino

This query

r.expr('été').split('')

Returns

["�","�","t","�","�"]

When I would expect

[é, t, é]

Putting in polish

Activity

  1. added this to the milestone on Jun 7, 2014
  2. mlucy commented on Jun 7, 2014

    @mlucy
    Member

    This is part of a more general "we don't support Unicode" issue. Changing this is kinda hard (we could special-case .split(''), but making split work with Unicode in general would be hard).

  3. modified the milestones: backlog, on Jun 7, 2014
  4. neumino commented on Jun 7, 2014

    @neumino
    MemberAuthor

    Moving in backlog for now then.

  5. AtnNn commented on Jun 9, 2014

    @AtnNn
    Member

    making split work with Unicode in general would be hard

    RethinkDB already bundles RE2 and ICU. Either of those could be used to help implement split('') for utf-8.

  6. mlucy commented on Jun 9, 2014

    @mlucy
    Member

    Ah, if we already have ICU it shouldn't be that hard.

  7. mlucy commented on Jun 9, 2014

    @mlucy
    Member

    (Note that we have to be careful that the result of split doesn't depend on the locale or the version of ICU installed on the machine (unless we provide our own static version), because otherwise it will no longer be deterministic and writes might diverge.)

  8. gchpaco commented on Dec 13, 2014

    @gchpaco
    Contributor

    It's actually very easy to do this by hand (UTF-8 is a self synchronizing format, and it's very easy to know when you're past a code point). I can actually do it if you think it valuable, but I think it would be better to use ICU's version when/if we include ICU into the rest of the system.

    You'll still have a different issue, which is that we will split combining characters away from their root code point. This is a much bigger issue to handle—you basically need a lookup table telling you whether the character in question is in the "M" category (most are Mn, some Indic scripts have Mcs, and then there's weird things like U+20DD for making 2⃝). This isn't difficult—the Unicode consortium have done all the intellectual spadework, which is represented in UnicodeData.txt and SpecialCasing.txt—but it would be better to use somebody else's library for this (probably ICU).

    If you want an example of what this looks like, consider the following query: r.expr("\u006f\u0301a va").split('o') which yields

    [
    "" ,
    "́a va"
    ]

    and yes, that is an accented quotation mark.

  9. gchpaco commented on Dec 13, 2014

    @gchpaco
    Contributor

    For what it's worth I don't care which version of Unicode we standardize on (a decision effectively determined by the version of ICU we decide to use). Unicode 7 added things like Mende Kikakui, which is used by less than 500 people. While I think it would be tragic if one of them tried to use our database and couldn't, I doubt it's worth worrying about.

  10. self-assigned this
    on Dec 13, 2014
  11. gchpaco commented on Dec 15, 2014

    @gchpaco
    Contributor

    Incidentally I checked other implementations for consistency on this. Python does not appear to support split(''). Ruby and node.js give the following results (here U+00E9 is é and U+0301 is the combining character for that accent):

    irb(main):001:0> "f\u00e9oo".split('')
    => ["f", "é", "o", "o"]
    irb(main):002:0> "fe\u0301oo".split('')
    => ["f", "e", "́", "o", "o"]

    and for node

    > "f\u00e9oo".split('')
    [ 'f', 'é', 'o', 'o' ]
    > "fe\u0301oo".split('')
    [ 'f',
      'e',
      '́',
      'o',
      'o' ]

    I am of the opinion that this is simply wrong. Whatever you are using split('') for, it is not well served by it handing you an accented quotation mark. I asked a friend of mine who doesn't have any particular interest in Unicode about it, and she agrees that, no matter what the actual codepoints look like, '́ is a crime against God and Man alike.

    If there is interest, we could probably add a decompose function that would actually split based on codepoints instead of semantically. I expect that almost no one would use it, however.

  12. danielmewes commented on Dec 15, 2014

    @danielmewes
    Member

    I agree that split should handle composed characters, and we should do it right even if Ruby and node.js don't.

    I don't think we need a decompose function. At least not until someone asks for it.

  13. 3 remaining items

  14. modified the milestones: 2.1, subsequent on Mar 24, 2015
  15. gchpaco commented on Mar 28, 2015

    @gchpaco
    Contributor

    CR 2754.

  16. mlucy commented on Mar 30, 2015

    @mlucy
    Member

    @danielmewes -- do you think we need to support the old behavior and force people to upgrade their indexes, or should we just assume nobody's depending on the old incorrect split behavior in an sindex function?

  17. danielmewes commented on Mar 30, 2015

    @danielmewes
    Member

    We should definitely bump the index ReQL version. (Maybe at some point we should think about scanning sindex functions for whether certain terms are used to decide whether an index is outdated, but let's not do that now.)

    We should only provide a backwards-compatible implementation for older indexes if it isn't much work.

  18. mlucy commented on Mar 30, 2015

    @mlucy
    Member

    It should be pretty easy; the old code doesn't need to be changed, we just need to branch and call it.

  19. mlucy commented on Mar 31, 2015

    @mlucy
    Member

    @gchpaco -- +1

    Do you know off the top of your head what other unicode-unaware operations we have lying around, if any? (Aside from lexicographic ordering, that is.)

  20. gchpaco commented on Apr 1, 2015

    @gchpaco
    Contributor

    #2950 comes to mind. There's the upcase/downcase thing, which is unicode unawares but not unicode-breaking. r.js needs to be inspected, but I'm not especially concerned because JS strings are supposed to be UTF-8 anyway. I will probably need to give r.match a once over to be sure.

    We just don't have very many string operations at present.

  21. modified the milestones: 2.2, 2.1 on May 7, 2015
  22. added a commit that references this issue on Aug 7, 2026
    3c06aca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions