Skip to content

fix: add heading hierarchy check and fix set -e crash#22

Merged
CybotTM merged 3 commits intomainfrom
fix/validate-heading-hierarchy
Feb 28, 2026
Merged

fix: add heading hierarchy check and fix set -e crash#22
CybotTM merged 3 commits intomainfrom
fix/validate-heading-hierarchy

Conversation

@CybotTM
Copy link
Member

@CybotTM CybotTM commented Feb 28, 2026

Summary

  • Bug fix: ((WARNINGS++)) with set -e crashes the script when counter is 0 (bash treats ((0)) as falsy exit code 1). All ((VAR++)) replaced with safe VAR=$((VAR + 1)) arithmetic.
  • New feature: Added TYPO3 heading hierarchy validation that catches:
    • First section heading not using = (h2) — the most common mistake when extracting sections into standalone pages
    • Non-standard underline characters (e.g. ^)
    • Skipped heading levels (e.g. h2 directly to h4 without h3)

Motivation

This was discovered during TYPO3-Documentation/TYPO3CMS-Guide-HowToDocument#510 where extracted pages retained their old heading levels. The validate_docs.sh script ran but never reached the heading check due to the set -e + ((0++)) crash, and even if it had, no heading hierarchy check existed.

Test plan

  • Run validate_docs.sh against a TYPO3 extension with correct headings — should pass
  • Run against a file where first section uses - instead of = — should flag it
  • Verify the set -e crash no longer occurs when first warning is encountered

…s.sh

Two issues fixed:

1. **Bug fix**: `((WARNINGS++))` and `((ERRORS++))` with `set -e` causes
   the script to exit prematurely when the counter is 0, because bash
   treats `((0))` as falsy (exit code 1). Replaced with
   `WARNINGS=$((WARNINGS + 1))` which always succeeds.

2. **New check**: Added TYPO3 heading hierarchy validation that detects:
   - First section heading not using `=` (h2) — catches the common issue
     where sections extracted from a parent page retain their old heading
     levels (e.g. `-` for h3 instead of `=` for h2)
   - Non-standard underline characters (e.g. `^` instead of `=/-/~`)
   - Skipped heading levels (e.g. h2 directly to h4 without h3)

   The check follows TYPO3 heading convention:
   - h1: `=` above and below (page title)
   - h2: `=` below only (sections)
   - h3: `-` below only (subsections)
   - h4: `~` below only (sub-subsections)

This would have caught the heading issues reported in
TYPO3-Documentation/TYPO3CMS-Guide-HowToDocument#510.

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the validate_docs.sh script that caused it to crash under specific conditions related to set -e and arithmetic operations. Concurrently, it introduces a significant enhancement by adding comprehensive validation for TYPO3 documentation heading structures, ensuring adherence to established guidelines and improving overall document quality.

Highlights

  • Bug Fix: set -e crash: Resolved a script crash when set -e was active and an arithmetic counter (e.g., ((VAR++))) was evaluated to zero, which Bash treats as a falsy exit code. All ((VAR++)) instances were replaced with VAR=$((VAR + 1)) for safe arithmetic.
  • New Feature: TYPO3 Heading Hierarchy Validation: Implemented a new check to validate TYPO3 documentation heading hierarchy. This includes verifying that the first section heading uses the correct = (h2) character, detecting non-standard underline characters, and identifying skipped heading levels (e.g., jumping from h2 to h4 without an h3).
Changelog
  • skills/typo3-docs/scripts/validate_docs.sh
    • Updated all instances of ((VAR++)) to VAR=$((VAR + 1)) to prevent script crashes when set -e is enabled and the counter is zero.
    • Introduced a new section for TYPO3 heading hierarchy validation, embedding a Python script to perform detailed checks on .rst files.
    • Added checks for the first section heading character, non-standard heading underline characters, and skipped heading levels.
Activity
  • The pull request author, CybotTM, created this PR to fix a known issue and introduce new validation features, as detailed in the summary and motivation sections.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a crash caused by set -e and ((VAR++)) arithmetic in bash, and introduces a new feature for validating heading hierarchy in RST files. However, the implementation of this new feature introduces a critical Command Injection and Python Code Injection vulnerability. This is due to the direct interpolation of a shell variable ($file) into a Python script executed via python3 -c, which could allow an attacker to execute arbitrary code. It is recommended to refactor the embedded Python code into a separate file to resolve this security risk and improve maintainability.

Move inline Python code from validate_docs.sh to validate_headings.py
to fix command injection vulnerability (shell variable $file was
interpolated directly into python3 -c code) and improve maintainability.

The filename is now passed securely as sys.argv[1].

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@CybotTM CybotTM merged commit 9b4cda1 into main Feb 28, 2026
7 checks passed
@CybotTM CybotTM deleted the fix/validate-heading-hierarchy branch February 28, 2026 17:51
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.

1 participant