website icon indicating copy to clipboard operation
website copied to clipboard

šŸ› Bug: Falsy check incorrectly treats index 0 as "not found" in JsonEditor component

Open shubhamkumar9199 opened this issue 1 month ago • 4 comments

Describe the bug

In components/JsonEditor.tsx, the hasCodeblockAsDescendant function is using a falsy check on the value returned by indexOf(). Since indexOf() returns 0 when the match is found at the very beginning of the string, the check treats that valid result as if nothing was found. Because of that, the function exits early whenever the code block appears at the start of the markdown content.

Steps To Reproduce

1.Open a markdown file where a JSON code block appears right at the beginning (index 0).

2.The JsonEditor component starts processing the markdown content.

3.During that process, the hasCodeblockAsDescendant check runs.

4.Since indexOf() returns 0 when it finds the code block at the start, the condition

if (!positionOfCodeInFullMarkdown) incorrectly evaluates to true.

As a result, the function exits early and skips handling code that should actually be processed.

Expected Behavior

The function should be able to detect and handle code blocks no matter where they appear in the markdown — even when a block starts right at index 0.

Screenshots

N/A — this is a logic-level bug, not a visual issue.

Device Information [optional]

- OS: Windows 10
- Browser: Chrome (latest)
- Version: Current codebase

Are you working on this issue?

Yes

Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)

No

shubhamkumar9199 avatar Nov 16 '25 07:11 shubhamkumar9199

will u plz assign me this issue , i am quite interested to work on it

dhiraj-143r avatar Nov 16 '25 09:11 dhiraj-143r

@dhiraj-143r I’m already working on this issue

shubhamkumar9199 avatar Nov 16 '25 09:11 shubhamkumar9199

ok

dhiraj-143r avatar Nov 16 '25 10:11 dhiraj-143r

@Utkarsh-123github Hi! Can you please assign me this issue? I’d like to work on it and fix it

shubhamkumar9199 avatar Nov 17 '25 09:11 shubhamkumar9199