Skip to content

fix(runner): keep backslashes and one row per result in markdown output - #2736

Merged
Mzack9999 merged 1 commit into
projectdiscovery:devfrom
VISHNU0906:fix/2735-markdown-escape
Nov 17, 2026
Merged

Mzack9999 merged 1 commit into
projectdiscovery:devfrom
VISHNU0906:fix/2735-markdown-escape

Conversation

@VISHNU0906

@VISHNU0906 VISHNU0906 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes #2735.

escapeMarkdown escaped pipes but not backslashes, so a literal \| in a field came out as \\| and GitHub showed it as |. It also only flattened \n, so a \r or \r\n inside a field (for example a generator meta value) started a new table row and pushed the later columns out of line.

This escapes backslashes along with pipes and turns CRLF, CR and LF into a single space.

Proof

  • New runner/md_output_test.go: table tests for escapeMarkdown and a MarkdownRow test with the title and generator values from the issue (plus a CRLF webserver value). Both fail on dev and pass with the change.
  • Rendered the repro row from the issue through GitHub's Markdown API: on dev it gives 3 table rows and the title shows left|right; with the change it gives the header plus 1 row, 53 cells for 53 headings, and the title shows left\|right.
  • go test ./..., golangci-lint run (v2.15.0, 0 issues), the two examples, integration_tests/run.sh (all passed) and the Windows/macOS builds of cmd/httpx.

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Markdown table output now handles backslashes and line breaks more safely, helping prevent cell contents from disrupting table formatting.
    • Results remain on a single table row, with cells aligned to the header.

escapeMarkdown escaped pipes but not backslashes, so a literal "\|" in a
field became "\\|" and GitHub rendered it without the backslash. It also only
flattened LF, so a CR or CRLF inside a field started a new table row and
shifted the following columns.

Escape backslashes along with pipes and turn CRLF, CR and LF into a space.

Fixes projectdiscovery#2735
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Markdown cell escaping now preserves literal backslashes before pipes and replaces CRLF and CR line endings with spaces. Tests verify escaping and confirm that rendered results remain one table row with the same cell count as the header.

Changes

Markdown Cell Escaping

Layer / File(s) Summary
Escape Markdown cells and validate rows
runner/md_output.go, runner/md_output_test.go
escapeMarkdown now escapes backslashes and pipes, and replaces CRLF, CR, and LF line endings with spaces. Tests cover these cases and check that rendered results stay on one row with the expected cell count.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: mzack9999

Merge Risk: Minimal · up to 7b15b

This change keeps literal backslashes before pipes and keeps each result on a single Markdown table row. It affects only Markdown output formatting, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: escaping backslashes in Markdown output and keeping one table row per result. The changeset escapes backslashes and pipes and replaces CR, CRLF, and LF in escapeM…
Linked Issues check Passed Issue #2735 requires two coding changes in Markdown cell output: keep literal backslashes before pipes, and flatten CR, CRLF and LF so each result stays on one row. At head, runner/md_output.go `escap…
Out of Scope Changes check Passed The PR changes two files: runner/md_output.go (escapeMarkdown, about +5/-0 lines) and the new runner/md_output_test.go (about +64 lines of tests). Both directly implement or test the objectives of #27…
Full details: Title check

Explanation

The title names the two main changes: escaping backslashes in Markdown output and keeping one table row per result. The changeset escapes backslashes and pipes and replaces CR, CRLF, and LF in escapeMarkdown, and adds tests for both behaviors. The title is specific and matches the linked issue's objectives. The 'fix(runner):' prefix is a conventional-commit style and does not affect relevance.

Full details: Linked Issues check

Explanation

Issue #2735 requires two coding changes in Markdown cell output: keep literal backslashes before pipes, and flatten CR, CRLF and LF so each result stays on one row. At head, runner/md_output.go escapeMarkdown uses a strings.NewReplacer that escapes \ to \\ and | to \|, and maps \r\n, \r and \n to a space. The \r\n pair is listed before \r, so CRLF becomes one space. The result is trimmed. For the issue title left\\|right, the cell now contains left\\\|right, which renders as left\|right. The generator value left\rright becomes left right and no longer starts a new row. MarkdownRow and formatMarkdownValue route string and slice values through escapeMarkdown, so the fix covers the reported fields. The PR adds runner/md_output_test.go with TestEscapeMarkdown and TestMarkdownRowKeepsOneRowPerResult for these cases. The test file was not read directly. Its coverage rests on the PR summary and the PR description. The whole-PR diff could not be read, so the base content of md_output.go was not compared line by line. The head implementation alone establishes the behavior.

Full details: Out of Scope Changes check

Explanation

The PR changes two files: runner/md_output.go (escapeMarkdown, about +5/-0 lines) and the new runner/md_output_test.go (about +64 lines of tests). Both directly implement or test the objectives of #2735. The change to escapeMarkdown applies to all Markdown string and slice fields. This is the code path the issue describes, so it is not an unrelated change. The PR description reports validation runs, and no unrelated code changes were identified in the summary. The whole-PR diff could not be read, so this verdict relies on the change summary and the head file contents.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each table line
Backslashes stay where they belong
CR and LF become a space
Each result holds its row in place
The header and its cells align
The rabbit hops away just fine

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab16bf8c-c814-4c34-bb9d-7073de204440
Commits

Reviewing files that changed from the base of the PR and between 9b6d807 and 7b15b5c.

Files selected for processing: 2

  • runner/md_output.go
  • runner/md_output_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Mzack9999
Mzack9999 merged commit eb38a2e into projectdiscovery:dev Nov 17, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

Markdown output loses backslashes before pipes and splits rows on carriage returns

2 participants