json-schema-org / json-schema-org/website

🐛 Bug: Falsy check incorrectly treats index 0 as "not found" in JsonEditor component

Open
#1,920 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 Bug Status: Triage
Dominant language
HTML
Stars
169
Forks
484
Avg merge
2d 2h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in components/JsonEditor.tsx and inspect hasCodeblockAsDescendant, focusing on the positionOfCodeInFullMarkdown check and its indexOf() result. Reproduce the case with a JSON code block at the beginning of markdown and verify that code blocks at index 0 are handled instead of being skipped.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.