CodeSampleX

샘플

league/csv 9.28.0: Read and write CSV with league/csv without losing a UTF-8 BOM, a quote, a trailing backslash or a whitespace-only field

검증된 샘플 — composer league/csv 9.28.0: Read and write CSV with league/csv without losing a UTF-8 BOM, a quote, a trailing backslash or a whitespace-only field.…

sha256:66f789bd06fd858b221bec119a5eed3fd6fd4cda52e9e99f9fca85b738d59a40

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 php 8 linux x64 php 8 php composer

검증 실행 환경

환경 컨트랙트 단계 실행일
php 8 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-14

케이스

HOW
목표
Read and write CSV with league/csv without losing a UTF-8 BOM, a quote, a trailing backslash or a whitespace-only field
패키지
심벌
  • League.Csv.Reader
  • League.Csv.Writer
  • League.Csv.Bom
  • League.Csv.SyntaxError
  • Reader::setHeaderOffset
  • AbstractCsv::skipInputBOM
  • AbstractCsv::includeInputBOM
  • AbstractCsv::setOutputBOM
  • AbstractCsv::setEscape
  • Writer::forceEnclosure
환경
php 8
생성일
2026-08-14T20:25:34Z

컨트랙트

  1. assert a UTF-8 BOM is already stripped by default so getHeader returns id, that calling skipInputBOM only restates the default, that getInputBOM still reports the BOM that was removed, and that a hand-rolled str_getcsv keeps it instead
  2. assert includeInputBOM is what puts the BOM back into the first header name, which turns the id lookup into a missing array key rather than an error, and that a quoted header sitting behind a BOM keeps its quotes as literal characters
  3. assert the input BOM is not carried into anything written back out, that setOutputBOM is the separate switch that restores it, and that a restored BOM is skipped again on the next read rather than accumulating
  4. assert a quote inside a field is doubled and drags an enclosure onto the whole field, that a quote which does not start a field is ordinary data, and that a malformed field parses to ab" with no error raised
  5. assert the default backslash escape makes a field ending in a backslash swallow the delimiter, the line ending and the entire next record into one field, that setEscape with an empty string on both ends restores both records, that setting it on the writer alone is not enough, and that a two character escape raises InvalidArgument
  6. assert setHeaderOffset makes the records associative and keeps the document offsets as their keys, so the first data record is at key 1 and key 0 is absent, while nth and first renumber from the first data row
  7. assert a duplicate header column passes setHeaderOffset and getHeader untouched but makes getRecords and count throw SyntaxError at the call site with duplicateColumnNames of id, and is harmless when no header offset is set
  8. assert a short row becomes a present key holding null, so array_key_exists and isset disagree about it, while an overlong row silently drops the field that has no header
  9. assert a field holding an embedded newline and a field holding only whitespace both survive a writer to reader round trip byte for byte, that a single space forces an enclosure while an empty field gets none, and that the embedded newline does not split the record
  10. assert whitespace is lost only for CSV written by something else, where a space before an enclosure is discarded together with both quotes while a space after the closing quote is kept and appended
  11. assert a zero byte line is dropped and takes its offset with it so the record keys jump, that includeEmptyRecords restores it as an empty array, and that a line holding a single space is never dropped
  12. assert encloseAll, encloseNecessary and encloseNone are predicates so calling encloseAll as if it were a setter changes nothing, that forceEnclosure quotes every field including the empty one, and that noEnclosure silently turns a field holding the delimiter into two fields
  13. assert createFromString still works but raises E_USER_DEPRECATED naming fromString as the replacement, while fromString carries no Deprecated attribute and createFromPath does

파일

  • composer.json
  • composer.lock
  • csx.json
  • phpunit.xml
  • src/Csv.php
  • test/CsvTest.php

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous