Skip to content

String operations with \r seem to mess things up, but only if \r immediately precedes \n #1071

@gesslar

Description

@gesslar

Strsrch

Evaluating: return strsrch("\nhello", "\n")
Result = 0
Evaluating: return strsrch("\r\nhello", "\n")
Result = -1
Evaluating: return strsrch("\n\rhello", "\n")
Result = 0

Sizeof/Strlen (sizeof returns the size as a strlen)__

Evaluating: return strlen("\nhello")
Result = 6
Evaluating: return strlen("\r\nhello")
Result = 6
Evaluating: return strlen("\n\rhello")
Result = 7

Directly accessing

Evaluating: return "\n"[0]
Result = 10
Evaluating: return "\r"[0]
Result = 13
Evaluating: return "\r\n"[0]
Result = 13
Evaluating: return "\r\n"[1]
Result = 0
(???????)

And finally, explode

Evaluating: return identify(explode("\r\n", ""))
Result = "({ "\r\n" })"
Evaluating: return identify(explode("hello\r\n", ""))
Result = "({ "h", "e", "l", "l", "o", "\r\n" })"
Evaluating: return identify(explode("\rhello\n", ""))
Result = "({ "\r", "h", "e", "l", "l", "o", "\n" })"
Evaluating: return identify(map(explode("hello\r\n", ""), (: $1[0] :)))
Result = "({ 104, 101, 108, 108, 111, 13 })"
Evaluating: return identify(map(explode("\rhello\n", ""), (: $1[0] :)))
Result = "({ 13, 104, 101, 108, 108, 111, 10 })"

Sscanf

Evaluating: string a, b; sscanf("\r\nAFB0\r\nmessage\r\n\0\r\n\r\n", "\r\n%s\r\n%s\r\n0\r\n\r\n", a, b); return ({ a, b }) ;

Result = ({ /* sizeof() == 2 */
  "AFB0",
  0
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions