Skip to content

[Bug]: LocalFilesystem grep corrupts JSON-escaped match text #4134

Open

Description

@Htd7860

Describe the bug

Local grep_files results do not preserve the matching text when ripgrep is installed. A line containing a double quote is cut off at the first escaped quote. Backslashes, tabs and line terminators remain JSON-escaped in the returned GrepMatch.text().

The search finds the right lines, but the agent sees different text from the file. For example, a source line needle = "hello"; is returned as needle = \.

To Reproduce

With rg on PATH:

Path root = Files.createTempDirectory("grep-repro-");
Files.writeString(root.resolve("source.txt"), "needle = \"hello\";\n");
var fs = new LocalFilesystem(root, true, 10);
var result = fs.grep(RuntimeContext.empty(), "needle", ".", null);
System.out.println(result.matches());

Expected behavior

The match text is needle = "hello";, without its line terminator. Quotes, backslashes and tabs should be the original characters, not their JSON representation.

Error messages

No exception is raised. The returned text is incorrect.

Environment

  • AgentScope Java: main at 2d70942c (2.1.0-SNAPSHOT)
  • Java 17, Windows 11, ripgrep 15.2.0

Additional context

LocalFilesystem.parseRipgrepJsonLine extracts strings by looking for the next ", without decoding JSON escapes. The real ripgrep/public grep path reproduces this, and eight regression cases fail on the original implementation. I am preparing a focused fix using the existing JSON codec; no new dependencies or search-policy changes are needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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