Skip to content

Displaying LF in CRLF shows 1:1 in line:col #117

Closed
@DaniPopes

Description

@DaniPopes

I wrote a test to demonstrate this:

#[test]
fn lf_in_crlf() {
    let source = "a\r\nb";
    let input = Level::Error.title("").snippet(
        Snippet::source(source)
            .origin("file/path")
            .line_start(3)
            .annotation(Level::Error.span(2..3)), // \n
    );
    let expected = str![[r#"
error
 --> file/path:1:1
  |
3 |   a
4 | | b
  | |_^
  |"#]]
    .indent(false);
    let renderer = Renderer::plain().anonymized_line_numbers(false);
    assert_eq(expected, renderer.render(input).to_string());
}

This only happens when a span points to exactly the \n byte that's preceded by \r

I believe this behavior is present since at least 0.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions