Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in UnifiedDiff::to_string method #37

Closed
sv-91 opened this issue Jul 28, 2022 · 3 comments
Closed

Crash in UnifiedDiff::to_string method #37

sv-91 opened this issue Jul 28, 2022 · 3 comments

Comments

@sv-91
Copy link

sv-91 commented Jul 28, 2022

This code crashes or produces incorrect output

    let fst = "\u{18}\n\n";
    let snd = "\n\n\r";

    let mut config = similar::TextDiffConfig::default();
    let diff = config.diff_lines(fst, snd);
    let mut output = diff.unified_diff();
    let result = output.context_radius(0).to_string();
    println!("Result:\n{}", result);
@mitsuhiko
Copy link
Owner

A context_radius of 0 does not make sense. I will add an explicit panic here in the internal function to make it error earlier.

@sv-91
Copy link
Author

sv-91 commented Jul 28, 2022

Yes, there are other examples here with different radius but with panic.
I don't understand, why there is needed explicit panic. I think, this is correct example, and it must work correctly.
You can change first symbol of fst to any other symbol, it doesn't matter

@mitsuhiko
Copy link
Owner

mitsuhiko commented Jul 28, 2022

As far as I can tell the example works fine with a non zero radius. I also believe the input data is irrelevant for the particular problem that a radius of 0 causes. What would you expect that a radius of 0 does? I will have another look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants