normalize_newlines & text_replaced should not use a dictionary

Bug #1190 reported by Carlos Perelló Marín
0
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Low
Unassigned

Bug Description

Dictionaries are unordered

Dictionaries are unordered. If I have text that is:

    \r\n\r\r\n

And the \r -> \n replacement runs first, I get

    \n\n\n\n\n

When \r\n replacement runs, nothing changes (no \r).

Now if the operation runs in reverse (\r\n -> \n first):

    \r\n\r\r\n

becomes

    \n\r\n

And then I suspect

    \n\n

Which is different. Isn't that a pretty evil bug? Why are we using
dictionaries?

Ah, by looking at text_replaced, I am seeing we iterate over
replacements.items() sorted by length, but I don't think that's the
right way to do it.. if we have clauses that do

    \n -> \r

    \r -> \x

    \x -> \n

Then the ordering matters very much.

Dafydd Harries (daf)
Changed in rosetta:
assignee: nobody → stevea
status: New → Accepted
Curtis Hovey (sinzui)
Changed in launchpad-foundations:
assignee: Steve Alexander (stevea) → nobody
Revision history for this message
Curtis Hovey (sinzui) wrote :

Rosetta is the only user of this ancient function.

visibility: private → public
affects: launchpad-foundations → rosetta
Changed in rosetta:
importance: Medium → Low
tags: added: tech-debt
removed: infrastructure
Revision history for this message
Curtis Hovey (sinzui) wrote :

normalize_newline was removed text_replaced now uses a different strategy

Changed in launchpad:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.