Context
YAML 1.2.2 requires processors to determine a stream's character encoding from a leading byte order mark or, when no mark is present, from the null-byte pattern in the first bytes. The module currently documents strict file decoding, but the remaining conformance work needs to cover BOM-less UTF-16/UTF-32 detection and explicit encoding mismatch behavior.
Official YAML 1.2.2 reference:
Current State
Import-Yaml detects byte order marks and defaults unmarked files to the caller's fallback encoding, defaulting to UTF-8. BOM-less UTF-16 and UTF-32 streams are not deduced from their null-byte pattern. A byte order mark currently wins over an explicit encoding argument instead of reporting a mismatch.
Objective
Make YAML file input conform to YAML 1.2.2 encoding detection while keeping PowerShell usage explicit, discoverable, and safe for pipeline-based file import.
PowerShell Design Considerations
- Keep
Import-Yaml as the byte-stream/file boundary; string-based commands should continue to operate on already-decoded text. - Preserve rich PowerShell errors with stable identifiers and path-aware target objects.
- Treat
-Encoding as an intentional caller assertion, not as an advisory fallback when a conflicting byte order mark exists. - Keep parameter behavior symmetric with any future file-import parameter sets and avoid ambiguous parameter sets that mix path resolution semantics with decoding semantics.
Tasks
Benefits
- Correctly imports valid YAML 1.2.2 files that omit a BOM but use UTF-16 or UTF-32.
- Prevents silently decoding files under a different encoding than the caller explicitly requested.
- Makes file import behavior predictable in automation and CI.
Acceptance Criteria
Related
- Spec folder:
spec/Encoding-Detection.md
Context
YAML 1.2.2 requires processors to determine a stream's character encoding from a leading byte order mark or, when no mark is present, from the null-byte pattern in the first bytes. The module currently documents strict file decoding, but the remaining conformance work needs to cover BOM-less UTF-16/UTF-32 detection and explicit encoding mismatch behavior.
Official YAML 1.2.2 reference:
docs/yaml-spec-1.2.2/06-chapter-character-productions/02-character-encodings/index.mdspec/Encoding-Detection.mdCurrent State
Import-Yamldetects byte order marks and defaults unmarked files to the caller's fallback encoding, defaulting to UTF-8. BOM-less UTF-16 and UTF-32 streams are not deduced from their null-byte pattern. A byte order mark currently wins over an explicit encoding argument instead of reporting a mismatch.Objective
Make YAML file input conform to YAML 1.2.2 encoding detection while keeping PowerShell usage explicit, discoverable, and safe for pipeline-based file import.
PowerShell Design Considerations
Import-Yamlas the byte-stream/file boundary; string-based commands should continue to operate on already-decoded text.-Encodingas an intentional caller assertion, not as an advisory fallback when a conflicting byte order mark exists.Tasks
YamlImportEncodingMismatch.YamlImportEncodingFailedfor malformed byte sequences.Benefits
Acceptance Criteria
-Encodingterminates withYamlImportEncodingMismatch.YamlImportEncodingFailedand emits no replacement characters.Related
spec/Encoding-Detection.md