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

Blank context lines are ignored by diff parser #485

Closed
Lordfirespeed opened this issue Mar 15, 2023 · 1 comment
Closed

Blank context lines are ignored by diff parser #485

Lordfirespeed opened this issue Mar 15, 2023 · 1 comment

Comments

@Lordfirespeed
Copy link

Lordfirespeed commented Mar 15, 2023

Step 0: Describe your environment

  • OS: Linux
  • diff2html version: NPM latest (3.4.33)
  • Using diff2html directly or using diff2html-ui helper: Directly
  • Extra flags:
    {
        drawFileList: true,
        matching: "lines",
        outputFormat: "line-by-line",
    }

Step 1: Describe the problem:

Blank context lines are being ignored by the diff parser

Steps to reproduce:

  1. Parse the diff2html.xyz demo diff
  2. Check the length of the first block of the first parsed file: it should be 9, with blank context lines at 0-indexes 6 and 8

Observed Results:

  • Blank content lines were omitted from the parsed diff object's lines array, it only has length 7 and line numbers are incorrect (although contiguous)
    image

Expected Results:

  • Blank content lines are included in the parsed diff object's lines array

Relevant Code:

export default function create_app() {
    const app = express();

    app.set("view engine", "ejs");

    app.get("/", async (request, response) => {
        const diff = await readFile("diffs/diff2htmldemo.diff", "utf-8");
        const parsed_diff = diff2html.parse(diff);
        const formatted_diff = diff2html.html(parsed_diff, {
            drawFileList: true,
            matching: "lines",
            outputFormat: "line-by-line",
        });
        response.render("pages/diff", { diff_tables: formatted_diff })
    });

    app.use("/", express.static("static"));
    app.use("/diff2html-bundles", express.static("node_modules/diff2html/bundles"));

    return app;
}
@Lordfirespeed
Copy link
Author

My IDE was removing the important leading whitespace at the beginning of blank context lines. Duh.

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

1 participant