## [Bug] Incorrect Escape Sequence Handling in C++ Playground Output #151

Closed
opened 2026-05-17 21:50:49 +00:00 by enjin2310 · 1 comment

Classification

Type: Bug
Priority: Medium
Component: C++ Playground / Output Validation

Summary

In the C++ Playground tool, the output validation incorrectly interprets escape sequences. The program executes successfully but fails the test due to a mismatch between expected and actual output caused by improper handling of newline characters.

Steps to Reproduce

  1. Navigate to learn.spikersoft.com/tools/cpp-playground.
  2. Enter the following code:
    #include <iostream>
    int main() {
        std::cout << "Hello, world!/n";
        return 0;
    }
    
### Classification **Type:** Bug **Priority:** Medium **Component:** C++ Playground / Output Validation ### Summary In the **C++ Playground** tool, the output validation incorrectly interprets escape sequences. The program executes successfully but fails the test due to a mismatch between expected and actual output caused by improper handling of newline characters. ### Steps to Reproduce 1. Navigate to [learn.spikersoft.com/tools/cpp-playground](https://learn.spikersoft.com/tools/cpp-playground). 2. Enter the following code: ```cpp #include <iostream> int main() { std::cout << "Hello, world!/n"; return 0; }
Owner

Fixed across both graders.

Root cause: C/C++ lesson stdout was compared byte-exactly in both the browser grader (ClangLessonGraderService) and the authoritative server-side grader (ClangLessonGradingExecutor). An otherwise-correct program failed over invisible trailing characters — a missing/extra final newline (std::endl vs "\n") or CRLF line endings — which is the "improper handling of newline characters" described here.

Fix: both graders now normalize line endings (CRLF/CR → LF) and trim trailing whitespace before comparing, while preserving internal newlines so multi-line output is still graded faithfully. Local (browser) and server grading stay in agreement.

  • Frontend: spikersoft-angular fix/issue-151-stdout-newline-tolerance (merged).
  • Backend: spikersoft-backend PR #6.

Note on the repro: the sample uses std::cout << "Hello, world!/n";/n (forward slash) is not an escape sequence, so the program prints the literal Hello, world!/n and correctly fails. The newline escape is \n (backslash). That specific line is a typo; this fix addresses the genuine latent defect it surfaced (brittle exact-match grading).

Fixed across both graders. **Root cause:** C/C++ lesson stdout was compared byte-exactly in both the browser grader (`ClangLessonGraderService`) and the authoritative server-side grader (`ClangLessonGradingExecutor`). An otherwise-correct program failed over invisible trailing characters — a missing/extra final newline (`std::endl` vs `"\n"`) or CRLF line endings — which is the "improper handling of newline characters" described here. **Fix:** both graders now normalize line endings (CRLF/CR → LF) and trim trailing whitespace before comparing, while preserving internal newlines so multi-line output is still graded faithfully. Local (browser) and server grading stay in agreement. - Frontend: spikersoft-angular `fix/issue-151-stdout-newline-tolerance` (merged). - Backend: spikersoft-backend PR #6. **Note on the repro:** the sample uses `std::cout << "Hello, world!/n";` — `/n` (forward slash) is not an escape sequence, so the program prints the literal `Hello, world!/n` and correctly fails. The newline escape is `\n` (backslash). That specific line is a typo; this fix addresses the genuine latent defect it surfaced (brittle exact-match grading).
Sign in to join this conversation.