Skip to content

Stdlib: highlight_file() emits raw newlines not <br /> between lines (ext/standard/highlight.c) #17557

Description

@PurHur

Category

Stdlib · php-src-strict

Problem

highlight_file($path, true) should wrap each source line in syntax-colored spans and join lines with <br /> inside a single outer <code> block (Zend). This compiler emits raw newlines inside <span> elements and omits <br /> separators.

Repro Zend 8.2+ VM (2026-07-09)
highlight_file($f, true) on "line1\nline2\n" — <br count 2 0
Raw \n inside highlighted span false true

php-src reference

PHP implementation target

  • ext/standard/highlight_file.php — line-split + <br /> join to match Zend HTML structure; reuse tokenizer output per line

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_highlight_file_br.php'

Done when

  • Multi-line file highlight matches Zend <br /> line breaks and outer <code> wrapper
  • show_source() alias agrees when applicable
  • Compliance .phpt under test/compliance/cases/stdlib/
  • php-src-strict

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 9, 2026
  2. PurHur commented on Jul 9, 2026

    @PurHur
    OwnerAuthor

    Maintainer repro committed on master: test/repro/maintainer_gap_*_57*.php — see issue body paths. Bootstrap gates 2026-07-09: link ✅ helloworld ✅ inventory 4311/4311 ✅

  3. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  4. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-b — starting this run

  5. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #17559.

    Fix: HighlightEngine::escapeAndFormat() now converts \n inside highlighted spans to <br />, matching php-src ext/standard/php_highlight.h. Shared by highlight_file(), highlight_string(), and show_source() on VM/JIT/AOT (HighlightJitHelper).

    Verification:

    • VM repro: php bin/vm.php test/repro/maintainer_gap_highlight_file_br.php → br_count=2, raw_nl_in_span=false
    • Compliance: vendor/bin/phpunit --filter highlight_file_br — OK (VM + JIT)
    • VmHighlightTest Zend byte-match — OK
    • AOT: highlight_string() multi-line → br-ok; -l on repro passes
  6. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged #17560

    Fix: HighlightEngine now converts newlines to <br /> inside highlight spans (php-src ext/standard/highlight.c) and colors T_INLINE_HTML as default black for plain-text file lines.

    Verification:

    ./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_highlight_file_br.php'
    # br_count=2 / content_newline=false / ok
    
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter highlight'
    # OK (28 tests)
    
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

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions