From 60c692f8a22f346753929e40aa3cb4053c9b0f32 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:22:13 -0500 Subject: [PATCH 1/8] =?UTF-8?q?upload-types=20=C2=B7=20slice=201:=20Upgrad?= =?UTF-8?q?e:=20docproc=20v0.13.0=20in=20the=20sub-modules,=20pin-project-?= =?UTF-8?q?lite=200.2.19?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - storage, postgres, and cmd/docproc require the base module at v0.13.0, through `mise run upgrade`. Their Unreleased bullet, which recorded the untagged move to v0.12.0, now reads v0.13.0, from v0.11.0, the version each module's last release required. - tools/mail and tools/onenote lock pin-project-lite 0.2.19, recorded under Unreleased in each tool's CHANGELOG. - Holds stay: tools/mail MimeKit 5.0.0 and MsgKit 3.1.0, tools/onenote typed-path 0.13.0. Nothing tagged. --- cmd/docproc/CHANGELOG.md | 2 +- cmd/docproc/go.mod | 2 +- cmd/docproc/go.sum | 4 ++-- postgres/CHANGELOG.md | 2 +- postgres/go.mod | 2 +- postgres/go.sum | 4 ++-- storage/CHANGELOG.md | 2 +- storage/go.mod | 2 +- storage/go.sum | 4 ++-- tools/mail/CHANGELOG.md | 2 ++ tools/mail/Cargo.lock | 4 ++-- tools/onenote/CHANGELOG.md | 2 ++ tools/onenote/Cargo.lock | 4 ++-- 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cmd/docproc/CHANGELOG.md b/cmd/docproc/CHANGELOG.md index 946053d..a6dd659 100644 --- a/cmd/docproc/CHANGELOG.md +++ b/cmd/docproc/CHANGELOG.md @@ -18,7 +18,7 @@ postgres modules, and each system tool under `tools/` keep their own. stays beside its `export_test.go`. The command line, run directory, and exit codes don't change. - `mise run build` at the repository root writes the docproc command to the git-ignored `bin/docproc`. -- The module requires the docproc base module at v0.12.0, from v0.11.0, whose +- The module requires the docproc base module at v0.13.0, from v0.11.0, whose [CHANGELOG](../../CHANGELOG.md) states its changes in full. - The module requires go-core v0.15.0, from v0.14.0; nothing `docproc run` does changes with it. diff --git a/cmd/docproc/go.mod b/cmd/docproc/go.mod index 765476a..42fa8a8 100644 --- a/cmd/docproc/go.mod +++ b/cmd/docproc/go.mod @@ -3,7 +3,7 @@ module github.com/standards-lab/docproc/cmd/docproc go 1.27.4 require ( - github.com/standards-lab/docproc v0.12.0 + github.com/standards-lab/docproc v0.13.0 github.com/standards-lab/go-cli-sdk v0.4.0 github.com/standards-lab/go-core v0.15.0 golang.org/x/sys v0.50.0 diff --git a/cmd/docproc/go.sum b/cmd/docproc/go.sum index 65bcb04..726a995 100644 --- a/cmd/docproc/go.sum +++ b/cmd/docproc/go.sum @@ -1,5 +1,5 @@ -github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg= -github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= +github.com/standards-lab/docproc v0.13.0 h1:WRvUFHvMM1eFxBr9sFkgRH7Co2GkW2jgrEvdflPY6Io= +github.com/standards-lab/docproc v0.13.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/go-cli-sdk v0.4.0 h1:232dyKPD5kqshp0BMEVEZaedwJfvnDVqWLv7m1NQWmI= github.com/standards-lab/go-cli-sdk v0.4.0/go.mod h1:7Y1BCcHtuu8Unxc+Hryjlln+0fbiMYa5xY75aueJ/rY= github.com/standards-lab/go-core v0.15.0 h1:yYjuUDlI7CupvtHJMT9Db7dAzNug3QJPGAEVruhIJI8= diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index d39a903..2e990b7 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -14,7 +14,7 @@ each system tool under `tools/` keep their own. - The module's unit tests and integration suite sit in its `test/` directory as an external test package. No exported API changes. -- The module requires the docproc base module at v0.12.0, from v0.11.0, and passes its +- The module requires the docproc base module at v0.13.0, from v0.11.0, and passes its `dispatchtest.Index` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes. ## [v0.1.9] - 2026-11-28 diff --git a/postgres/go.mod b/postgres/go.mod index 21c0a76..0567e7d 100644 --- a/postgres/go.mod +++ b/postgres/go.mod @@ -4,7 +4,7 @@ go 1.27.4 require ( github.com/jackc/pgx/v5 v5.13.0 - github.com/standards-lab/docproc v0.12.0 + github.com/standards-lab/docproc v0.13.0 github.com/standards-lab/sqlate v0.8.0 github.com/standards-lab/sqlate/postgres v0.9.0 ) diff --git a/postgres/go.sum b/postgres/go.sum index 8444874..37dd6a6 100644 --- a/postgres/go.sum +++ b/postgres/go.sum @@ -13,8 +13,8 @@ github.com/jackc/puddle/v2 v2.2.3 h1:f8HoREISb3l5eO9coPgK7U3hKLhWGokOFVcThl5jrao github.com/jackc/puddle/v2 v2.2.3/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg= -github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= +github.com/standards-lab/docproc v0.13.0 h1:WRvUFHvMM1eFxBr9sFkgRH7Co2GkW2jgrEvdflPY6Io= +github.com/standards-lab/docproc v0.13.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/sqlate v0.8.0 h1:G1uUIWmc2DxJz5YhtBvIlftfURnb3b2RKsYB59Wa03Y= github.com/standards-lab/sqlate v0.8.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= github.com/standards-lab/sqlate/postgres v0.9.0 h1:l6PXEZ3GQM4+0zekxlSONhyHjpQU8g8StAS16bBqzZE= diff --git a/storage/CHANGELOG.md b/storage/CHANGELOG.md index 24cf061..5235d5d 100644 --- a/storage/CHANGELOG.md +++ b/storage/CHANGELOG.md @@ -14,7 +14,7 @@ each system tool under `tools/` keep their own. - The module's unit tests and integration suite sit in its `test/` directory as an external test package. No exported API changes. -- The module requires the docproc base module at v0.12.0, from v0.11.0, and passes its +- The module requires the docproc base module at v0.13.0, from v0.11.0, and passes its `dispatchtest.Content` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes. ## [v0.1.9] - 2026-11-28 diff --git a/storage/go.mod b/storage/go.mod index 0527bb4..ee72954 100644 --- a/storage/go.mod +++ b/storage/go.mod @@ -3,7 +3,7 @@ module github.com/standards-lab/docproc/storage go 1.27.4 require ( - github.com/standards-lab/docproc v0.12.0 + github.com/standards-lab/docproc v0.13.0 github.com/standards-lab/go-storage v0.8.0 github.com/standards-lab/go-storage/s3 v0.3.0 ) diff --git a/storage/go.sum b/storage/go.sum index 883c785..5947d8e 100644 --- a/storage/go.sum +++ b/storage/go.sum @@ -36,8 +36,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.52.0 h1:IaBLmJWiIEtKkjXMgMbYGZk7WKXb github.com/aws/aws-sdk-go-v2/service/sts v1.52.0/go.mod h1:MG6N8U9+lY4LqchrlHPqCOSr7hyxw70XU0Et2YR3eNA= github.com/aws/smithy-go v1.28.9 h1:zkZ058OpNX0iGTK24b+ZUEQSMc11CBA6oO7xtKZfzkY= github.com/aws/smithy-go v1.28.9/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc= -github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg= -github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= +github.com/standards-lab/docproc v0.13.0 h1:WRvUFHvMM1eFxBr9sFkgRH7Co2GkW2jgrEvdflPY6Io= +github.com/standards-lab/docproc v0.13.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/go-core v0.12.0 h1:sqrzK6QSppEYpwvVAyiWgzNuOsjfK0Kwe86GPuZpHsU= github.com/standards-lab/go-core v0.12.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= github.com/standards-lab/go-storage v0.8.0 h1:r2irs88NfmHRzBBOd9eTYdgS4rqrR6pm/aLaLiL/Gd4= diff --git a/tools/mail/CHANGELOG.md b/tools/mail/CHANGELOG.md index 45286fd..8b46995 100644 --- a/tools/mail/CHANGELOG.md +++ b/tools/mail/CHANGELOG.md @@ -19,6 +19,8 @@ output contract: a change to them is a change here. This changelog covers docpro - The crate graph locks byteorder 1.5.1 and sha2 0.11.3, patch releases, in place of 1.5.0 and 0.11.2, the latter yanked; the envelope crate's lock takes sha2 0.11.3 too. The output is unchanged. +- The crate graph locks pin-project-lite 0.2.19, a patch release, in place of 0.2.18. The output is + unchanged. ## [v0.2.0] - 2026-11-25 diff --git a/tools/mail/Cargo.lock b/tools/mail/Cargo.lock index f8b54d4..29df344 100644 --- a/tools/mail/Cargo.lock +++ b/tools/mail/Cargo.lock @@ -552,9 +552,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" +checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe" [[package]] name = "potential_utf" diff --git a/tools/onenote/CHANGELOG.md b/tools/onenote/CHANGELOG.md index ecf693d..5c238ec 100644 --- a/tools/onenote/CHANGELOG.md +++ b/tools/onenote/CHANGELOG.md @@ -17,6 +17,8 @@ covers docproc-onenote only. - The crate graph locks byteorder 1.5.1 and sha2 0.11.3, patch releases, in place of 1.5.0 and 0.11.2, the latter yanked; the envelope crate's lock takes sha2 0.11.3 too. The output is unchanged. +- The crate graph locks pin-project-lite 0.2.19, a patch release, in place of 0.2.18. The output is + unchanged. ## [v0.1.2] - 2026-11-23 diff --git a/tools/onenote/Cargo.lock b/tools/onenote/Cargo.lock index 65a4630..4c5b7d2 100644 --- a/tools/onenote/Cargo.lock +++ b/tools/onenote/Cargo.lock @@ -515,9 +515,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" +checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe" [[package]] name = "potential_utf" From 592fffa58ae394be232190820a09c238e241d631 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:27:56 -0500 Subject: [PATCH 2/8] =?UTF-8?q?upload-types=20=C2=B7=20slice=202:=20route'?= =?UTF-8?q?s=20text=20test,=20a=20head=20of=20no=20control=20byte,=20UTF-8?= =?UTF-8?q?=20or=20windows-1252?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content of no routed signature, or that fails a claim's own check, is text only when its first HeadLen bytes hold no control byte (C0 but tab, LF, FF, CR; DEL) and are valid UTF-8 with no C1 code point, or windows-1252 without its five undefined bytes. The NUL-only test is gone from every fallback: no signature, the OLE2 and mbox claims, and the .eml or message-typed header. route.At and route.MediaType share it. A byte order mark still makes content text ahead of the test. Decisions: - A rune cut off at the head's end is valid when the content runs past the head (len(head) < size), whatever the head's length, not only at HeadLen. - A C1 code point in valid UTF-8 makes the head not text; the same bytes are not retried as windows-1252. - storedMedia's stored audio or video type routes content whose head isn't text by the new test, since its doc ties it to the fallback's refusal. Test changed: file_test's "escape and bell" is unrouted, not text. --- CHANGELOG.md | 13 ++++++ docs/api.md | 2 +- docs/limits.md | 7 +++- route/doc.go | 15 ++++--- route/route.go | 92 +++++++++++++++++++++++++++++++---------- route/test/at_test.go | 55 ++++++++++++++++++++++++ route/test/file_test.go | 2 +- 7 files changed, 155 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cdcf4e..61a4368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,19 @@ tool under `tools/` keeps its own. ## [Unreleased] +### Changed + +- **Breaking:** content of no routed signature, or that fails a claim's own check, is text only + when its first `route.HeadLen` bytes hold no control byte, a C0 control other than tab, line + feed, form feed, or carriage return, or DEL, and are valid UTF-8 holding no C1 control, a rune + cut off at the head's end allowed when the content runs past it, or windows-1252 without its + five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. Before, any head without a NUL byte was + text. Content with a control byte but no NUL byte, such as a log holding terminal escapes, and + content that is neither UTF-8 nor windows-1252 now routes `route.Unrouted`, and + `route.MediaType` types it application/octet-stream, not text/plain. Content stored as an audio + or video type routes by it when its head isn't text by the same test. A byte order mark still + makes content text ahead of the test. + ## [v0.13.0] - 2026-12-02 This release adds `route.MediaType`, the media type of content as `route.At` routes it, on `At`'s diff --git a/docs/api.md b/docs/api.md index 010bb71..ee0d41c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -931,7 +931,7 @@ What each stage yields, and why, beside the `Meta` keys `dispatch` documents on images, embedded files, and ink, is found at `page , media `, named by the name it was inserted or attached under, else by its media name; one with no content written, its data missing or invalid, is a failed child. A recording, an embedded file of type `audio` or `video`, carries - that type as its stored type, so content of no signature route knows, a NUL in its head, is + that type as its stored type, so content of no signature route knows, its head not text, is routed by it. A page's ink is an SVG, routed vision-converted, to the picture stage's PNG. A skipped section is an unread child at `skipped section `: encrypted for a password-protected one, else failed. - **audio.** No model runs: the stage prepares the windows a layer above transcribes and joins, and diff --git a/docs/limits.md b/docs/limits.md index 3c475e6..be155e6 100644 --- a/docs/limits.md +++ b/docs/limits.md @@ -5,8 +5,11 @@ an unencrypted one that is not a text, spreadsheet, presentation, or drawing doc such as a formula, chart, database, or image package (`.odf`, `.odc`, `.odb`, `.odi`), with no processor yet. ISO routes to no stage. docproc runs no virus scan and flags no macro in an OLE2 file. Content no processor claims is read as text, whatever its name, when its first 4096 bytes hold -no NUL byte, and is unrouted when they do. So HTML and an EPUB's entries are read as raw text, with -no structure, and UTF-16 without a byte order mark, which holds NULs, is refused. docproc detects no +no control byte (a C0 control other than tab, line feed, form feed, or carriage return, or DEL) and +are valid UTF-8 with no C1 control, a rune cut off at the 4096th byte allowed, or windows-1252 +without its five undefined bytes (0x81, 0x8D, 0x8F, 0x90, 0x9D); otherwise it is unrouted. So HTML +and an EPUB's entries are read as raw text, with no structure, and UTF-16 without a byte order mark, +which holds NULs, and a log holding terminal escapes are refused. docproc detects no text's encoding: it reads text by its byte order mark, as UTF-8, or else as windows-1252, so a legacy multibyte encoding such as Shift-JIS, EUC-JP, or ISO-2022-JP reads as mojibake. Beyond that, each stage inherits its tool's limits, as the tools' READMEs diff --git a/route/doc.go b/route/doc.go index 87ac734..b204875 100644 --- a/route/doc.go +++ b/route/doc.go @@ -23,7 +23,7 @@ // for a cabinet, and for content of no signature, which is a message by the .eml rule. A name's // extension never makes content text, nor does a stored audio or video type make text media. // Content no route claims, or that fails a claim's own check, falls back on its head: text when -// its first [HeadLen] bytes hold no NUL byte, and unrouted when they do, its reason the claim it +// its first [HeadLen] bytes are text, and unrouted when they aren't, its reason the claim it // failed, or "no routed signature", then ", text by its head" or ", not text"; content named .eml // or stored as a message whose header isn't a message's shape is the exception, its reason "a // message by its , but not header-shaped", then "; text by its head" when it is @@ -34,6 +34,11 @@ // whole for an EncryptedPackage stream's directory entry, by [EncryptedPackage], which inspect // calls too; an mbox is read past its "From " line for a message's header; and content of no // signature is read for a message's header, a header after a UTF-8 byte order mark among them. +// A head is text when it holds no control byte, a C0 control other than tab, line feed, form +// feed, or carriage return, or DEL, and is either valid UTF-8 holding no C1 control, U+0080 +// through U+009F, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and +// 0x9D; a rune the head cuts off at its end is valid when the content runs past the head. A byte +// order mark makes content text ahead of the test, so UTF-16 and UTF-32 marked by one are text. // The routes: // // - [Document]: a PDF, for the document package's stage. @@ -57,11 +62,11 @@ // - [Archive]: a ZIP that is neither office's nor ODF, a tar, gzip, zstd, 7z, RAR4, RAR5, xz, // or bzip2 archive, or a cabinet not named .onepkg. // - [Audio]: WAV, FLAC, MP3, an Ogg that begins no video stream, or M4A; or content of no -// signature stored as an audio type whose head holds a NUL byte. +// signature stored as an audio type whose head isn't text. // - [Video]: MP4, Matroska, WebM, AVI, an MPEG program stream, or an Ogg video; or content of -// no signature stored as a video type whose head holds a NUL byte. +// no signature stored as a video type whose head isn't text. // - [Text]: content marked by a byte order mark; a script, by its "#!" line; and the -// fallback's content whose head holds no NUL byte, whatever its name or stored audio or video +// fallback's content whose head is text, whatever its name or stored audio or video // type: HTML, CSS, JavaScript, an EPUB's entries, a .txt, .csv, or .json, a LICENSE, prose // that begins "From " without a message header, or content named .eml or stored as a message // whose header isn't a message's shape, but for an SVG, which routes by its root element. @@ -69,7 +74,7 @@ // executable; an .ost, whose reason names it, since mail refuses one; an XPS package, a ZIP // holding FixedDocumentSequence.fdseq, whole or as its first piece, whatever its name, ahead // of the OOXML rules, since one is an OPC package too and may be named .docx; and the -// fallback's content whose head holds a NUL byte, an OLE2 compound file without a legacy or +// fallback's content whose head isn't text, an OLE2 compound file without a legacy or // .msg extension, an mbox's "From " line without a message header, and content named .eml or // stored as a message whose header isn't a message's shape among it. // diff --git a/route/route.go b/route/route.go index 8e1ae56..7b178f1 100644 --- a/route/route.go +++ b/route/route.go @@ -9,6 +9,7 @@ import ( "os" "path" "strings" + "unicode/utf8" ) // Route names the stage content goes to next, for the caller to run, as the package doc lists @@ -54,24 +55,28 @@ const ( Archive Route = "archive" // Audio is WAV, FLAC, MP3, an Ogg that begins no video stream, or M4A; and content of no // signature whose stored MIME type's top-level type is audio and whose first [HeadLen] bytes - // hold a NUL byte, so the fallback refuses it as text. + // aren't text, as [Text] reads them, so the fallback refuses it as text. Audio Route = "audio" // Video is MP4, Matroska, WebM, AVI, an MPEG program stream, or an Ogg that begins a Theora, // VP8, Dirac, or OGM video stream; and content of no signature whose stored MIME type's - // top-level type is video and whose first [HeadLen] bytes hold a NUL byte, so the fallback - // refuses it as text. + // top-level type is video and whose first [HeadLen] bytes aren't text, as [Text] reads them, + // so the fallback refuses it as text. Video Route = "video" // Text is content that begins with a UTF-8, UTF-16, or UTF-32 byte order mark; a script, by // its "#!" line; and, as the fallback, content no other route claims, or that fails a - // claim's own check, whose first [HeadLen] bytes hold no NUL byte, whatever its name or - // stored audio or video type: HTML, CSS, JavaScript, an EPUB's entries, a .txt, .csv, or + // claim's own check, whose first [HeadLen] bytes are text, whatever its name or stored audio + // or video type: HTML, CSS, JavaScript, an EPUB's entries, a .txt, .csv, or // .json, a LICENSE, prose that begins "From " without a message header, or a mislabelled // attachment stored as audio among it. Its reason ends ", text by its head" and begins with // the claim it failed, such as "OLE2 signature without a legacy or .msg extension", `mbox // "From " line without a message header`, or "no routed signature"; for content named .eml or // stored as a message whose header isn't a message's shape, it is "a message by its , but not header-shaped; text by its head". A name's extension never makes content - // text. + // text. A head is text when it holds no control byte, a C0 control other than tab, line feed, + // form feed, or carriage return, or DEL, and is either valid UTF-8 holding no C1 control, + // U+0080 through U+009F, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, + // 0x90, and 0x9D. A rune the head cuts off at its end is valid when the content runs past the + // head, and invalid when the content ends there. Text Route = "text" // Unrouted is a deliberate refusal: an executable, by a PE, ELF, or Mach-O signature; an XPS // package, a ZIP holding a FixedDocumentSequence.fdseq entry, whole or as its first piece, @@ -79,7 +84,8 @@ const ( // named .docx; and an .ost, an offline store mail refuses. It is the fallback's too: content // no other route claims, or that fails a claim's own check, such as an OLE2 compound file // without a legacy or .msg extension, nor an encrypted OOXML package's stream and name, or an - // mbox's "From " line without a message header, whose first [HeadLen] bytes hold a NUL byte. + // mbox's "From " line without a message header, whose first [HeadLen] bytes aren't text, as + // [Text] reads them: a control byte, or bytes neither UTF-8 nor windows-1252 reads. // Its reason then ends ", not text" and begins with the claim it failed, or "no routed // signature"; for content named .eml or stored as a message whose header isn't a message's // shape, it is "a message by its , but not header-shaped". @@ -232,13 +238,14 @@ func File(path, name, mimeType string) (Route, string, error) { // whose first line is a field: an mbox is [Nested] only with one, and content of no signature, or // of a UTF-8 byte order mark, with one is a message whatever its name. Content of no signature // Identify knows whose mimeType's top-level type is audio or video, such as a OneNote recording's -// stored "audio", routes Audio or Video only when head holds a NUL byte. Content no route claims, +// stored "audio", routes Audio or Video only when head isn't text. Content no route claims, // an OLE2 compound file without a legacy or .msg extension, nor an encrypted OOXML package's stream // and name, an mbox without a message's header, and content named .eml or stored as a message whose -// header isn't a message's shape fall back on head: [Text] when it holds no NUL byte, [Unrouted] -// when it does. It returns an error only for r's own. +// header isn't a message's shape fall back on head: [Text] when it is text, as Text's doc reads +// a head, and [Unrouted] when it isn't. It returns an error only for r's own. func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, string, error) { head = head[:min(len(head), HeadLen)] + cut := int64(len(head)) < size ext := Ext(name) kind := Identify(head) switch kind { @@ -275,10 +282,10 @@ func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, s return Nested, `mbox "From " line`, nil } claim := `mbox "From " line without a message header` - route, why := fallBack(head, claim+", text by its head", claim+", not text") + route, why := fallBack(head, cut, claim+", text by its head", claim+", not text") return route, why, nil } - if route, why := byKind(kind, ext, head); route != "" { + if route, why := byKind(kind, ext, head, cut); route != "" { return route, why, nil } readHeader := func() (headerFields, error) { return header(io.NewSectionReader(r, 0, size)) } @@ -289,12 +296,12 @@ func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, s return "", "", err case !fields.shaped(): claim := "a message by its " + as + ", but not header-shaped" - route, why := fallBack(head, claim+"; text by its head", claim) + route, why := fallBack(head, cut, claim+"; text by its head", claim) return route, why, nil } return Nested, "a message by its " + as + ", header-shaped", nil } - if r := storedMedia(mimeType); r != "" && kind == Unknown && holdsNUL(head) { + if r := storedMedia(mimeType); r != "" && kind == Unknown && !textual(head, cut) { return r, "no known signature, stored as " + mimeType, nil } if kind == Unknown || kind == UTF8BOM { @@ -310,18 +317,59 @@ func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, s return Text, "text by its " + bom + " byte order mark", nil } const unclaimed = "no routed signature" - route, why := fallBack(head, unclaimed+", text by its head", unclaimed+", not text") + route, why := fallBack(head, cut, unclaimed+", text by its head", unclaimed+", not text") return route, why, nil } -func fallBack(head []byte, textWhy, notTextWhy string) (Route, string) { - if holdsNUL(head) { - return Unrouted, notTextWhy +func fallBack(head []byte, cut bool, textWhy, notTextWhy string) (Route, string) { + if textual(head, cut) { + return Text, textWhy } - return Text, textWhy + return Unrouted, notTextWhy } -func holdsNUL(head []byte) bool { return bytes.IndexByte(head, 0) >= 0 } +func textual(head []byte, cut bool) bool { + for _, b := range head { + if b < 0x20 && b != '\t' && b != '\n' && b != '\f' && b != '\r' || b == 0x7f { + return false + } + } + if whole, ok := utf8Whole(head, cut); ok { + for len(whole) > 0 { + r, n := utf8.DecodeRune(whole) + if r >= 0x80 && r <= 0x9f { + return false + } + whole = whole[n:] + } + return true + } + for _, b := range head { + switch b { + case 0x81, 0x8d, 0x8f, 0x90, 0x9d: + return false + } + } + return true +} + +func utf8Whole(head []byte, cut bool) ([]byte, bool) { + if utf8.Valid(head) { + return head, true + } + if !cut { + return nil, false + } + for i := len(head) - 1; i >= max(len(head)-utf8.UTFMax+1, 0); i-- { + if utf8.RuneStart(head[i]) { + if !utf8.FullRune(head[i:]) && utf8.Valid(head[:i]) { + return head[:i], true + } + return nil, false + } + } + return nil, false +} func mboxHeader(r io.Reader) (headerFields, error) { br := bufio.NewReaderSize(r, headerLineMax) @@ -350,7 +398,7 @@ func storedMedia(mimeType string) Route { return "" } -func byKind(kind Kind, ext string, head []byte) (Route, string) { +func byKind(kind Kind, ext string, head []byte, cut bool) (Route, string) { if r, ok := kindRoutes[kind]; ok { return r.route, r.why } @@ -371,7 +419,7 @@ func byKind(kind Kind, ext string, head []byte) (Route, string) { return Nested, "OLE2 signature, .msg extension" } claim := "OLE2 signature without a legacy or .msg extension" - return fallBack(head, claim+", text by its head", claim+", not text") + return fallBack(head, cut, claim+", text by its head", claim+", not text") case MSCF: if ext == ".onepkg" { return OneNote, "cabinet signature, .onepkg extension" diff --git a/route/test/at_test.go b/route/test/at_test.go index 5835e3f..5e4cf37 100644 --- a/route/test/at_test.go +++ b/route/test/at_test.go @@ -89,6 +89,61 @@ func TestAtContent(t *testing.T) { } } +func TestAtText(t *testing.T) { + const ( + byHead = "no routed signature, text by its head" + notText = "no routed signature, not text" + noHeader = `mbox "From " line without a message header, not text` + eml = "a message by its .eml extension, but not header-shaped" + ) + padded := strings.Repeat("a", route.HeadLen-2) + cases := []struct { + name, content, filename, mime string + want route.Route + why, media string + }{ + {"utf-8", "café, naïve, 日本語, 😀\n", "a.txt", "", route.Text, byHead, "text/plain"}, + {"utf-8 rune cut at the head's end", padded + "\u2041 more", "a.txt", "", route.Text, byHead, "text/plain"}, + {"utf-8 four-byte rune cut at the head's end", padded + "😀 more", "a.txt", "", route.Text, byHead, "text/plain"}, + {"utf-8 rune cut where the content ends", "abc\xe2\x81", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"utf-8 rune cut where a head of HeadLen ends", padded + "\xe2\x81", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"utf-8 c1 control", "a\u0085b\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"windows-1252", "caf\xe9 \x93quoted\x94 \x80 5\n", "menu.txt", "", route.Text, byHead, "text/plain"}, + {"windows-1252 undefined 0x81", "caf\xe9 \x81\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"windows-1252 undefined 0x8d", "caf\xe9 \x8d\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"windows-1252 undefined 0x8f", "caf\xe9 \x8f\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"windows-1252 undefined 0x90", "caf\xe9 \x90\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"windows-1252 undefined 0x9d", "caf\xe9 \x9d\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"start of heading", "a\x01b\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"escape", "\x1b[31mred\x1b[0m\n", "build.log", "", route.Unrouted, notText, "application/octet-stream"}, + {"vertical tab", "a\vb\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"delete", "a\x7fb\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"tab, line feed, carriage return, form feed", "a\tb\r\nc\fd\n", "a.txt", "", route.Text, byHead, "text/plain"}, + {"a control past the head", strings.Repeat("a", route.HeadLen) + "\x1b", "a.txt", "", route.Text, byHead, "text/plain"}, + {"utf-16 little-endian bom", "\xff\xfeh\x00i\x00\n\x00", "a.txt", "", route.Text, "text by its UTF-16 byte order mark", "text/plain"}, + {"mbox line with an escape", "From the desk of Ann\n\x1b[0m\n", "", "", route.Unrouted, noHeader, "application/mbox"}, + {"eml not header-shaped, an escape", "Dear Bob,\x1bhello\n", "a.eml", "", route.Unrouted, eml, "application/octet-stream"}, + {"an escape stored as audio", "a\x1bb", "a.mp3", "audio/mpeg", route.Audio, "no known signature, stored as audio/mpeg", "application/octet-stream"}, + {"windows-1252 stored as audio", "caf\xe9\n", "a.mp3", "audio/mpeg", route.Text, byHead, "text/plain"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + r := strings.NewReader(c.content) + head := []byte(c.content[:min(len(c.content), route.HeadLen)]) + got, why, err := route.At(r, int64(len(c.content)), head, c.filename, c.mime) + if err != nil { + t.Fatal(err) + } + if got != c.want || why != c.why { + t.Errorf("route %q (%s), want %q (%s)", got, why, c.want, c.why) + } + if got := mediaType(t, c.content, c.filename, c.mime); got != c.media { + t.Errorf("MediaType = %q, want %q", got, c.media) + } + }) + } +} + func TestAtNearClaims(t *testing.T) { const ( separator = "From ann@example.org Sat Jan 3 01:05:34 1996\n" diff --git a/route/test/file_test.go b/route/test/file_test.go index 8d17686..3a4d38b 100644 --- a/route/test/file_test.go +++ b/route/test/file_test.go @@ -99,7 +99,7 @@ func TestFileRoutes(t *testing.T) { {"notice", "This product includes software\n", "NOTICE", "", route.Text, byHead}, {"transcript of an unlisted extension", "[00:01] Ann: hello\n", "call.transcript", "", route.Text, byHead}, {"windows-1252 text", "caf\xe9 \x93quoted\x94 \x80 5\n", "menu.txt", "", route.Text, byHead}, - {"escape and bell", "\x1b[31mred\x1b[0m\a\n", "build.log", "", route.Text, byHead}, + {"escape and bell", "\x1b[31mred\x1b[0m\a\n", "build.log", "", route.Unrouted, notText}, {"nul in the head", "plain\x00text", "a.txt", "text/plain", route.Unrouted, notText}, {"nul as the head's last byte", strings.Repeat("a", route.HeadLen-1) + "\x00", "a.txt", "", route.Unrouted, notText}, {"nul past the head", strings.Repeat("a", route.HeadLen) + "\x00", "a.txt", "", route.Text, byHead}, From 1fda2bbbc5c25a3ac0d0e2e739cf0c692975c541 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:32:40 -0500 Subject: [PATCH 3/8] =?UTF-8?q?upload-types=20=C2=B7=20slice=203:=20route.?= =?UTF-8?q?MediaType=20types=20text=20by=20extension=20and=20HEIF=20by=20b?= =?UTF-8?q?rand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Text of no signature (At's head-text fallback) takes its type from route's own extension table, by Ext: .md/.markdown, .csv, .tsv, .html/.htm, .xml, .json, .yaml/.yml, .css, .js/.mjs, .ics, .vcf; any other is text/plain. BOM and shebang kinds still type text/plain via kindTypes before At runs, so the table applies on the fallback path alone. No mime.TypeByExtension. - A HEIC's type comes from its ftyp major brand: image/heic, heic-sequence, heif, or heif-sequence. majorBrand is extracted from isISOBMFF and shared; HEIC leaves kindTypes since heifTypes covers every brand Identify maps to HEIC (heicBrands and structuralBrands). Routing is unchanged. - CHANGELOG Unreleased ### Changed, MediaType's doc comment, route/doc.go's inventory, and docs/api.md's route block state the table and the brands. --- CHANGELOG.md | 10 +++++++ docs/api.md | 6 ++++ route/doc.go | 9 ++++-- route/identify.go | 11 +++++-- route/media.go | 46 ++++++++++++++++++++++++++--- route/test/media_test.go | 62 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61a4368..cadce41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,16 @@ tool under `tools/` keeps its own. `route.MediaType` types it application/octet-stream, not text/plain. Content stored as an audio or video type routes by it when its head isn't text by the same test. A byte order mark still makes content text ahead of the test. +- `route.MediaType` types content of no signature that routes `route.Text` by its name's + extension, by `route.Ext`, from route's own table: text/markdown for .md or .markdown, text/csv + for .csv, text/tab-separated-values for .tsv, text/html for .html or .htm, application/xml for + .xml, application/json for .json, application/yaml for .yaml or .yml, text/css for .css, + text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf; any other + extension stays text/plain, as does text marked by a byte order mark or a script's "#!" line. + Content that isn't text stays application/octet-stream whatever its name. +- `route.MediaType` types a `route.HEIC` by its ftyp box's major brand: image/heic for heic, heix, + heim, or heis; image/heic-sequence for hevc or hevx; image/heif for heif, mif1, or miaf; and + image/heif-sequence for msf1. Before, every HEIC was image/heic. Its route is unchanged. ## [v0.13.0] - 2026-12-02 diff --git a/docs/api.md b/docs/api.md index ee0d41c..a3b6b3e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -96,6 +96,12 @@ func Identify(head []byte) Kind // at most HeadLe func File(path, name, mimeType string) (Route, string, error) // the route, and why func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, string, error) func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error) + // a Kind's type; a HEIC's by its major brand: heic, heix, heim, heis image/heic; hevc, hevx + // image/heic-sequence; heif, mif1, miaf image/heif; msf1 image/heif-sequence. Text of no + // signature by Ext from route's table: .md, .markdown text/markdown; .csv text/csv; .tsv + // text/tab-separated-values; .html, .htm text/html; .xml application/xml; .json + // application/json; .yaml, .yml application/yaml; .css text/css; .js, .mjs text/javascript; + // .ics text/calendar; .vcf text/vcard; any other text/plain. Not text: octet-stream func Ext(name string) string // trimmed and lowercased func EncryptedPackage(r io.ReaderAt, size int64) (bool, error) // an OLE2 EncryptedPackage func RARVolume(head []byte) bool // a RAR's main header marks a volume diff --git a/route/doc.go b/route/doc.go index b204875..9ce8d77 100644 --- a/route/doc.go +++ b/route/doc.go @@ -96,9 +96,12 @@ // - [File] routes the file at a path, and says why; [At] routes content already open. // - [MediaType] gives the media type of content as At routes it, on At's inputs: a [Kind]'s // type by its signature; within a ZIP, an ODF package, or an OLE2 compound file, the name's -// extension first, for an OOXML, OpenDocument, or legacy office type, .msg's, or .zip's; and, -// for content of no signature, text/plain, message/rfc822, or application/octet-stream by -// its route. +// extension first, for an OOXML, OpenDocument, or legacy office type, .msg's, or .zip's; a +// HEIC's by its ftyp box's major brand, image/heic, image/heic-sequence, image/heif, or +// image/heif-sequence; and, for content of no signature, message/rfc822 or +// application/octet-stream by its route, or, for [Text], a type by the name's extension from +// route's own table, such as text/markdown for .md, text/csv for .csv, or application/json +// for .json, and text/plain for an extension outside it. // - [Ext] reads a name's extension; [OOXMLExtension] reports whether it is an OOXML // package's, the one table of them; [LegacyTarget] gives the OOXML format a legacy // extension converts to, the one table of those; [EncryptedPackage] reports whether an OLE2 diff --git a/route/identify.go b/route/identify.go index 0149912..4690685 100644 --- a/route/identify.go +++ b/route/identify.go @@ -425,10 +425,10 @@ func isRIFF(head []byte) Kind { } func isISOBMFF(head []byte) Kind { - if len(head) < 12 || string(head[4:8]) != "ftyp" { + major, ok := majorBrand(head) + if !ok { return Unknown } - major := brand(head[8:12]) boxLen := min(int(binary.BigEndian.Uint32(head)), len(head)) var compatible []string for i := 16; i+4 <= boxLen; i += 4 { @@ -452,6 +452,13 @@ func isISOBMFF(head []byte) Kind { return MP4 } +func majorBrand(head []byte) (string, bool) { + if len(head) < 12 || string(head[4:8]) != "ftyp" { + return "", false + } + return brand(head[8:12]), true +} + func brand(b []byte) string { return string(bytes.TrimRight(b, " \x00")) } diff --git a/route/media.go b/route/media.go index 1c6335b..661985e 100644 --- a/route/media.go +++ b/route/media.go @@ -18,7 +18,6 @@ var kindTypes = map[Kind]string{ EMF: "image/emf", WMF: "image/wmf", SVG: "image/svg+xml", - HEIC: "image/heic", WebP: "image/webp", AVIF: "image/avif", ZIP: zipType, @@ -59,6 +58,31 @@ var kindTypes = map[Kind]string{ UTF32BOM: textPlain, } +var heifTypes = map[string]string{ + "heic": "image/heic", "heix": "image/heic", "heim": "image/heic", "heis": "image/heic", + "hevc": "image/heic-sequence", "hevx": "image/heic-sequence", + "heif": "image/heif", "mif1": "image/heif", "miaf": "image/heif", + "msf1": "image/heif-sequence", +} + +var textTypes = map[string]string{ + ".md": "text/markdown", + ".markdown": "text/markdown", + ".csv": "text/csv", + ".tsv": "text/tab-separated-values", + ".html": "text/html", + ".htm": "text/html", + ".xml": "application/xml", + ".json": "application/json", + ".yaml": "application/yaml", + ".yml": "application/yaml", + ".css": "text/css", + ".js": "text/javascript", + ".mjs": "text/javascript", + ".ics": "text/calendar", + ".vcf": "text/vcard", +} + var zipTypes = map[string]string{ ".zip": zipType, ".odt": "application/vnd.oasis.opendocument.text", @@ -85,15 +109,26 @@ const outlookType = "application/vnd.ms-outlook" // application/vnd.ms-powerpoint, or application/vnd.ms-outlook for .msg. Otherwise the [Kind] // head's signature names decides, such as application/pdf for a [PDF], application/zip for a ZIP // or an ODF package, application/x-ole-storage for an OLE2 compound file, application/mbox for an -// mbox, and text/plain for a script or a byte order mark. Content of no signature takes the route -// At gives it, with name and mimeType: text/plain for [Text], message/rfc822 for [Nested], and -// application/octet-stream otherwise. It returns an error only for r's own. +// mbox, and text/plain for a script or a byte order mark. A [HEIC] takes its type from its ftyp +// box's major brand: image/heic for heic, heix, heim, or heis; image/heic-sequence for hevc or +// hevx; image/heif for heif, mif1, or miaf; and image/heif-sequence for msf1. Content of no +// signature takes the route At gives it, with name and mimeType: message/rfc822 for [Nested]; +// application/octet-stream for any route but [Text], whatever its name; and, for Text, a type by +// name's extension, text/markdown for .md or .markdown, text/csv for .csv, +// text/tab-separated-values for .tsv, text/html for .html or .htm, application/xml for .xml, +// application/json for .json, application/yaml for .yaml or .yml, text/css for .css, +// text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf, or text/plain +// for any other. It returns an error only for r's own. func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error) { head = head[:min(len(head), HeadLen)] kind := Identify(head) if t := containerType(kind, Ext(name)); t != "" { return t, nil } + if kind == HEIC { + major, _ := majorBrand(head) + return heifTypes[major], nil + } if t, ok := kindTypes[kind]; ok { return t, nil } @@ -103,6 +138,9 @@ func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (s } switch routed { case Text: + if t, ok := textTypes[Ext(name)]; ok { + return t, nil + } return textPlain, nil case Nested: return "message/rfc822", nil diff --git a/route/test/media_test.go b/route/test/media_test.go index e403f16..ac92cfa 100644 --- a/route/test/media_test.go +++ b/route/test/media_test.go @@ -165,6 +165,68 @@ func TestMediaTypeFallBack(t *testing.T) { } } +func TestMediaTypeTextByExtension(t *testing.T) { + const words = "the minutes of the meeting\n" + cases := []struct { + name, content, filename, want string + }{ + {"md", words, "notes.md", "text/markdown"}, + {"markdown", words, "notes.markdown", "text/markdown"}, + {"csv", words, "table.csv", "text/csv"}, + {"tsv", words, "table.tsv", "text/tab-separated-values"}, + {"html", words, "page.html", "text/html"}, + {"htm", words, "page.htm", "text/html"}, + {"xml", words, "feed.xml", "application/xml"}, + {"json", words, "data.json", "application/json"}, + {"yaml", words, "config.yaml", "application/yaml"}, + {"yml", words, "config.yml", "application/yaml"}, + {"css", words, "site.css", "text/css"}, + {"js", words, "app.js", "text/javascript"}, + {"mjs", words, "app.mjs", "text/javascript"}, + {"ics", words, "invite.ics", "text/calendar"}, + {"vcf", words, "card.vcf", "text/vcard"}, + {"uppercase, trailing dot", words, "NOTES.MD.", "text/markdown"}, + {"unknown extension", words, "notes.txt", "text/plain"}, + {"no extension", words, "README", "text/plain"}, + {"not text named .md", "a\x01b\n", "notes.md", "application/octet-stream"}, + {"not text named .json", "a\x01b\n", "data.json", "application/octet-stream"}, + {"utf-8 bom named .md", "\xef\xbb\xbf# notes\n", "notes.md", "text/plain"}, + {"shebang named .js", "#!/usr/bin/env node\nconsole.log(1)\n", "app.js", "text/plain"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := mediaType(t, c.content, c.filename, ""); got != c.want { + t.Errorf("MediaType = %q, want %q", got, c.want) + } + }) + } +} + +func TestMediaTypeHEIFBrands(t *testing.T) { + cases := []struct { + name, content, want string + }{ + {"heic", ftyp("heic", "mif1", "heic"), "image/heic"}, + {"heix", ftyp("heix", "mif1", "heix"), "image/heic"}, + {"heim", ftyp("heim", "mif1", "heim"), "image/heic"}, + {"heis", ftyp("heis", "mif1", "heis"), "image/heic"}, + {"hevc", ftyp("hevc", "msf1", "hevc"), "image/heic-sequence"}, + {"hevx", ftyp("hevx", "msf1", "hevx"), "image/heic-sequence"}, + {"heif", ftyp("heif", "mif1", "heif"), "image/heif"}, + {"mif1", ftyp("mif1", "mif1", "heic"), "image/heif"}, + {"miaf", ftyp("miaf", "miaf", "mif1"), "image/heif"}, + {"msf1", ftyp("msf1", "msf1", "hevc"), "image/heif-sequence"}, + {"iphone", ftyp("heic", "mif1", "MiHE", "MiPr", "miaf", "MiHB", "heic"), "image/heic"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := mediaType(t, c.content, "IMG_0001.HEIC", ""); got != c.want { + t.Errorf("MediaType = %q, want %q", got, c.want) + } + }) + } +} + type failingReader struct{ err error } func (f failingReader) ReadAt([]byte, int64) (int, error) { return 0, f.err } From 77f1d64055370c62d89f8917b0a0e7194e9cb59f Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:37:11 -0500 Subject: [PATCH 4/8] =?UTF-8?q?upload-types=20=C2=B7=20docproc=20=C2=B7=20?= =?UTF-8?q?standards=20review:=20textual=20ranges=20the=20head's=20runes?= =?UTF-8?q?=20in=20place=20of=20decoding=20them=20by=20hand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/route.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/route/route.go b/route/route.go index 7b178f1..2c30b0b 100644 --- a/route/route.go +++ b/route/route.go @@ -335,12 +335,10 @@ func textual(head []byte, cut bool) bool { } } if whole, ok := utf8Whole(head, cut); ok { - for len(whole) > 0 { - r, n := utf8.DecodeRune(whole) + for _, r := range string(whole) { if r >= 0x80 && r <= 0x9f { return false } - whole = whole[n:] } return true } From a9de2ec4ac57903bf595b1cec7cd66cfd19744a0 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:37:13 -0500 Subject: [PATCH 5/8] =?UTF-8?q?upload-types=20=C2=B7=20docproc=20=C2=B7=20?= =?UTF-8?q?standards=20review:=20Unreleased=20becomes=20[v0.14.0]=20-=2020?= =?UTF-8?q?26-12-02=20per=20release-and-ci.md,=20compare=20links=20extende?= =?UTF-8?q?d,=20README's=20go=20get=20names=20v0.14.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 ++++++++- README.md | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cadce41..0b19700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ tool under `tools/` keeps its own. ## [Unreleased] +## [v0.14.0] - 2026-12-02 + +This release narrows what `route.At` reads as text: a head holding a control byte, or bytes +neither UTF-8 nor windows-1252, is no longer text. It also has `route.MediaType` type text of no +signature by its name's extension, and a HEIC by its major brand. + ### Changed - **Breaking:** content of no routed signature, or that fails a claim's own check, is text only @@ -768,7 +774,8 @@ fixtures scripts stay in the spike. The [limits page](docs/limits.md) states them: each stage's tool's limits, docproc-ooxml's behavior under a memory bound, the Threader's memory, and the formats no stage reads. -[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.13.0...HEAD +[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.14.0...HEAD +[v0.14.0]: https://github.com/standards-lab/docproc/compare/v0.13.0...v0.14.0 [v0.13.0]: https://github.com/standards-lab/docproc/compare/v0.12.0...v0.13.0 [v0.12.0]: https://github.com/standards-lab/docproc/compare/v0.11.0...v0.12.0 [v0.11.0]: https://github.com/standards-lab/docproc/compare/v0.10.0...v0.11.0 diff --git a/README.md b/README.md index cf07483..3c58e0f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ tags. ## Install ```sh -go get github.com/standards-lab/docproc@v0.13.0 +go get github.com/standards-lab/docproc@v0.14.0 ``` The module's releases are tagged `vX.Y.Z`, and [`CHANGELOG.md`](CHANGELOG.md) states what each From 31f0397e3dc892c428ce3910d74d75d203aab857 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:43:09 -0500 Subject: [PATCH 6/8] =?UTF-8?q?upload-types=20=C2=B7=20docproc=20=C2=B7=20?= =?UTF-8?q?spec=20gap=201:=20a=20valid-UTF-8=20head=20holding=20a=20C1=20c?= =?UTF-8?q?ode=20point=20is=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The approved brief tests control bytes only (C0 besides tab, LF, CR, FF, and DEL); textual also refused a valid-UTF-8 head holding U+0080-U+009F, a rule the brief doesn't have. The rule is removed: a head such as 61 C2 85 62 0A is valid UTF-8 with no control byte, so it is text. utf8Whole becomes utf8Head, returning only whether the head is UTF-8, since no caller needs the trimmed slice any more. The 'utf-8 c1 control' case in route/test/at_test.go now expects route.Text and text/plain. The C1 mention is dropped from the Text constant's doc, route/doc.go, docs/limits.md, and the CHANGELOG [v0.14.0] Breaking entry. --- CHANGELOG.md | 3 +-- docs/limits.md | 2 +- route/doc.go | 5 ++--- route/route.go | 25 ++++++++----------------- route/test/at_test.go | 2 +- 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b19700..533207e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,7 @@ signature by its name's extension, and a HEIC by its major brand. - **Breaking:** content of no routed signature, or that fails a claim's own check, is text only when its first `route.HeadLen` bytes hold no control byte, a C0 control other than tab, line - feed, form feed, or carriage return, or DEL, and are valid UTF-8 holding no C1 control, a rune - cut off at the head's end allowed when the content runs past it, or windows-1252 without its + feed, form feed, or carriage return, or DEL, and are valid UTF-8, a rune cut off at the head's end allowed when the content runs past it, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. Before, any head without a NUL byte was text. Content with a control byte but no NUL byte, such as a log holding terminal escapes, and content that is neither UTF-8 nor windows-1252 now routes `route.Unrouted`, and diff --git a/docs/limits.md b/docs/limits.md index be155e6..54af953 100644 --- a/docs/limits.md +++ b/docs/limits.md @@ -6,7 +6,7 @@ such as a formula, chart, database, or image package (`.odf`, `.odc`, `.odb`, `. processor yet. ISO routes to no stage. docproc runs no virus scan and flags no macro in an OLE2 file. Content no processor claims is read as text, whatever its name, when its first 4096 bytes hold no control byte (a C0 control other than tab, line feed, form feed, or carriage return, or DEL) and -are valid UTF-8 with no C1 control, a rune cut off at the 4096th byte allowed, or windows-1252 +are valid UTF-8, a rune cut off at the 4096th byte allowed, or windows-1252 without its five undefined bytes (0x81, 0x8D, 0x8F, 0x90, 0x9D); otherwise it is unrouted. So HTML and an EPUB's entries are read as raw text, with no structure, and UTF-16 without a byte order mark, which holds NULs, and a log holding terminal escapes are refused. docproc detects no diff --git a/route/doc.go b/route/doc.go index 9ce8d77..0e627ac 100644 --- a/route/doc.go +++ b/route/doc.go @@ -35,9 +35,8 @@ // calls too; an mbox is read past its "From " line for a message's header; and content of no // signature is read for a message's header, a header after a UTF-8 byte order mark among them. // A head is text when it holds no control byte, a C0 control other than tab, line feed, form -// feed, or carriage return, or DEL, and is either valid UTF-8 holding no C1 control, U+0080 -// through U+009F, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and -// 0x9D; a rune the head cuts off at its end is valid when the content runs past the head. A byte +// feed, or carriage return, or DEL, and is either valid UTF-8 or windows-1252 without its five +// undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D; a rune the head cuts off at its end is valid when the content runs past the head. A byte // order mark makes content text ahead of the test, so UTF-16 and UTF-32 marked by one are text. // The routes: // diff --git a/route/route.go b/route/route.go index 2c30b0b..dd72e6b 100644 --- a/route/route.go +++ b/route/route.go @@ -73,9 +73,8 @@ const ( // stored as a message whose header isn't a message's shape, it is "a message by its , but not header-shaped; text by its head". A name's extension never makes content // text. A head is text when it holds no control byte, a C0 control other than tab, line feed, - // form feed, or carriage return, or DEL, and is either valid UTF-8 holding no C1 control, - // U+0080 through U+009F, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, - // 0x90, and 0x9D. A rune the head cuts off at its end is valid when the content runs past the + // form feed, or carriage return, or DEL, and is either valid UTF-8 or windows-1252 without + // its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. A rune the head cuts off at its end is valid when the content runs past the // head, and invalid when the content ends there. Text Route = "text" // Unrouted is a deliberate refusal: an executable, by a PE, ELF, or Mach-O signature; an XPS @@ -334,12 +333,7 @@ func textual(head []byte, cut bool) bool { return false } } - if whole, ok := utf8Whole(head, cut); ok { - for _, r := range string(whole) { - if r >= 0x80 && r <= 0x9f { - return false - } - } + if utf8Head(head, cut) { return true } for _, b := range head { @@ -351,22 +345,19 @@ func textual(head []byte, cut bool) bool { return true } -func utf8Whole(head []byte, cut bool) ([]byte, bool) { +func utf8Head(head []byte, cut bool) bool { if utf8.Valid(head) { - return head, true + return true } if !cut { - return nil, false + return false } for i := len(head) - 1; i >= max(len(head)-utf8.UTFMax+1, 0); i-- { if utf8.RuneStart(head[i]) { - if !utf8.FullRune(head[i:]) && utf8.Valid(head[:i]) { - return head[:i], true - } - return nil, false + return !utf8.FullRune(head[i:]) && utf8.Valid(head[:i]) } } - return nil, false + return false } func mboxHeader(r io.Reader) (headerFields, error) { diff --git a/route/test/at_test.go b/route/test/at_test.go index 5e4cf37..6da3e7d 100644 --- a/route/test/at_test.go +++ b/route/test/at_test.go @@ -107,7 +107,7 @@ func TestAtText(t *testing.T) { {"utf-8 four-byte rune cut at the head's end", padded + "😀 more", "a.txt", "", route.Text, byHead, "text/plain"}, {"utf-8 rune cut where the content ends", "abc\xe2\x81", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, {"utf-8 rune cut where a head of HeadLen ends", padded + "\xe2\x81", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, - {"utf-8 c1 control", "a\u0085b\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, + {"utf-8 c1 control", "a\u0085b\n", "a.txt", "", route.Text, byHead, "text/plain"}, {"windows-1252", "caf\xe9 \x93quoted\x94 \x80 5\n", "menu.txt", "", route.Text, byHead, "text/plain"}, {"windows-1252 undefined 0x81", "caf\xe9 \x81\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, {"windows-1252 undefined 0x8d", "caf\xe9 \x8d\n", "a.txt", "", route.Unrouted, notText, "application/octet-stream"}, From 355d9698f39784e4c501dce77701fe9bb8c84c28 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:45:47 -0500 Subject: [PATCH 7/8] upload-types: rewrap the text test's doc and changelog entry --- CHANGELOG.md | 18 +++++++++--------- route/route.go | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 533207e..3015cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,15 +17,15 @@ signature by its name's extension, and a HEIC by its major brand. ### Changed -- **Breaking:** content of no routed signature, or that fails a claim's own check, is text only - when its first `route.HeadLen` bytes hold no control byte, a C0 control other than tab, line - feed, form feed, or carriage return, or DEL, and are valid UTF-8, a rune cut off at the head's end allowed when the content runs past it, or windows-1252 without its - five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. Before, any head without a NUL byte was - text. Content with a control byte but no NUL byte, such as a log holding terminal escapes, and - content that is neither UTF-8 nor windows-1252 now routes `route.Unrouted`, and - `route.MediaType` types it application/octet-stream, not text/plain. Content stored as an audio - or video type routes by it when its head isn't text by the same test. A byte order mark still - makes content text ahead of the test. +- **Breaking:** content of no routed signature, or that fails a claim's own check, is text only when + its first `route.HeadLen` bytes hold no control byte, a C0 control other than tab, line feed, form + feed, or carriage return, or DEL, and are valid UTF-8, a rune cut off at the head's end allowed + when the content runs past it, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, + 0x90, and 0x9D. Before, any head without a NUL byte was text. Content with a control byte but no + NUL byte, such as a log holding terminal escapes, and content that is neither UTF-8 nor + windows-1252 now routes `route.Unrouted`, and `route.MediaType` types it application/octet-stream, + not text/plain. Content stored as an audio or video type routes by it when its head isn't text by + the same test. A byte order mark still makes content text ahead of the test. - `route.MediaType` types content of no signature that routes `route.Text` by its name's extension, by `route.Ext`, from route's own table: text/markdown for .md or .markdown, text/csv for .csv, text/tab-separated-values for .tsv, text/html for .html or .htm, application/xml for diff --git a/route/route.go b/route/route.go index dd72e6b..5e47de5 100644 --- a/route/route.go +++ b/route/route.go @@ -74,8 +74,8 @@ const ( // type>, but not header-shaped; text by its head". A name's extension never makes content // text. A head is text when it holds no control byte, a C0 control other than tab, line feed, // form feed, or carriage return, or DEL, and is either valid UTF-8 or windows-1252 without - // its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. A rune the head cuts off at its end is valid when the content runs past the - // head, and invalid when the content ends there. + // its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. A rune the head cuts off at its + // end is valid when the content runs past the head, and invalid when the content ends there. Text Route = "text" // Unrouted is a deliberate refusal: an executable, by a PE, ELF, or Mach-O signature; an XPS // package, a ZIP holding a FixedDocumentSequence.fdseq entry, whole or as its first piece, From 00f78fa7cee6913e68818a916ae1fbb0553a9fd1 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 2 Dec 2026 12:49:49 -0500 Subject: [PATCH 8/8] upload-types: editor pass on the text test, media types, and release notes --- CHANGELOG.md | 37 +++++++++++++++++++------------------ docs/api.md | 15 ++++++--------- docs/limits.md | 18 +++++++++--------- route/doc.go | 9 +++++---- route/media.go | 2 +- route/route.go | 10 +++++----- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3015cc7..83c3e11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,28 +11,29 @@ tool under `tools/` keeps its own. ## [v0.14.0] - 2026-12-02 -This release narrows what `route.At` reads as text: a head holding a control byte, or bytes -neither UTF-8 nor windows-1252, is no longer text. It also has `route.MediaType` type text of no +This release narrows what `route.At` reads as text: a head that holds a control byte, or whose +bytes are neither UTF-8 nor windows-1252, is no longer text. `route.MediaType` now types text of no signature by its name's extension, and a HEIC by its major brand. ### Changed -- **Breaking:** content of no routed signature, or that fails a claim's own check, is text only when - its first `route.HeadLen` bytes hold no control byte, a C0 control other than tab, line feed, form - feed, or carriage return, or DEL, and are valid UTF-8, a rune cut off at the head's end allowed - when the content runs past it, or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, - 0x90, and 0x9D. Before, any head without a NUL byte was text. Content with a control byte but no - NUL byte, such as a log holding terminal escapes, and content that is neither UTF-8 nor - windows-1252 now routes `route.Unrouted`, and `route.MediaType` types it application/octet-stream, - not text/plain. Content stored as an audio or video type routes by it when its head isn't text by - the same test. A byte order mark still makes content text ahead of the test. -- `route.MediaType` types content of no signature that routes `route.Text` by its name's - extension, by `route.Ext`, from route's own table: text/markdown for .md or .markdown, text/csv - for .csv, text/tab-separated-values for .tsv, text/html for .html or .htm, application/xml for - .xml, application/json for .json, application/yaml for .yaml or .yml, text/css for .css, - text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf; any other - extension stays text/plain, as does text marked by a byte order mark or a script's "#!" line. - Content that isn't text stays application/octet-stream whatever its name. +- **Breaking:** content of no routed signature, or content that fails a claim's own check, is text + only when its first `route.HeadLen` bytes pass two tests. They hold no control byte, meaning no + C0 control other than tab, line feed, form feed, or carriage return, and no DEL. They are also + either valid UTF-8 or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and + 0x9D; a UTF-8 rune cut off at the head's end is allowed when the content runs past the head. + Before, any head without a NUL byte was text. Content with a control byte but no NUL byte, such + as a log holding terminal escapes, and content that is neither UTF-8 nor windows-1252 now routes + `route.Unrouted`, and `route.MediaType` types it application/octet-stream, not text/plain. + Content stored as an audio or video type routes by that type when its head fails the same tests. + A byte order mark still makes content text before the tests run. +- `route.MediaType` types content of no signature that routes `route.Text` by its name's extension, + as `route.Ext` reads it, from a table in the `route` package: text/markdown for .md or .markdown, + text/csv for .csv, text/tab-separated-values for .tsv, text/html for .html or .htm, + application/xml for .xml, application/json for .json, application/yaml for .yaml or .yml, text/css + for .css, text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf; any + other extension stays text/plain, as does text marked by a byte order mark or a script's "#!" + line. Content that isn't text stays application/octet-stream whatever its name. - `route.MediaType` types a `route.HEIC` by its ftyp box's major brand: image/heic for heic, heix, heim, or heis; image/heic-sequence for hevc or hevx; image/heif for heif, mif1, or miaf; and image/heif-sequence for msf1. Before, every HEIC was image/heic. Its route is unchanged. diff --git a/docs/api.md b/docs/api.md index a3b6b3e..f108949 100644 --- a/docs/api.md +++ b/docs/api.md @@ -96,12 +96,8 @@ func Identify(head []byte) Kind // at most HeadLe func File(path, name, mimeType string) (Route, string, error) // the route, and why func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, string, error) func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error) - // a Kind's type; a HEIC's by its major brand: heic, heix, heim, heis image/heic; hevc, hevx - // image/heic-sequence; heif, mif1, miaf image/heif; msf1 image/heif-sequence. Text of no - // signature by Ext from route's table: .md, .markdown text/markdown; .csv text/csv; .tsv - // text/tab-separated-values; .html, .htm text/html; .xml application/xml; .json - // application/json; .yaml, .yml application/yaml; .css text/css; .js, .mjs text/javascript; - // .ics text/calendar; .vcf text/vcard; any other text/plain. Not text: octet-stream + // a Kind's type, a HEIC's by its major brand; text of no signature by Ext from route's + // table, else text/plain; content that isn't text application/octet-stream func Ext(name string) string // trimmed and lowercased func EncryptedPackage(r io.ReaderAt, size int64) (bool, error) // an OLE2 EncryptedPackage func RARVolume(head []byte) bool // a RAR's main header marks a volume @@ -937,9 +933,10 @@ What each stage yields, and why, beside the `Meta` keys `dispatch` documents on images, embedded files, and ink, is found at `page , media `, named by the name it was inserted or attached under, else by its media name; one with no content written, its data missing or invalid, is a failed child. A recording, an embedded file of type `audio` or `video`, carries - that type as its stored type, so content of no signature route knows, its head not text, is - routed by it. A page's ink is an SVG, routed vision-converted, to the picture stage's PNG. A skipped section is an - unread child at `skipped section `: encrypted for a password-protected one, else failed. + that type as its stored type, so content of no signature route knows is routed by that type when + its head isn't text. A page's ink is an SVG, routed vision-converted, to the picture stage's PNG. + A skipped section is an unread child at `skipped section `: encrypted for a + password-protected one, else failed. - **audio.** No model runs: the stage prepares the windows a layer above transcribes and joins, and the plan it joins them by. Each window is yielded as the part's one decode cuts it, in plan order, `window N`, a 16 kHz mono 16-bit PCM WAV named by its SHA-256, its `Meta` carrying what a caller diff --git a/docs/limits.md b/docs/limits.md index 54af953..cc748af 100644 --- a/docs/limits.md +++ b/docs/limits.md @@ -5,15 +5,15 @@ an unencrypted one that is not a text, spreadsheet, presentation, or drawing doc such as a formula, chart, database, or image package (`.odf`, `.odc`, `.odb`, `.odi`), with no processor yet. ISO routes to no stage. docproc runs no virus scan and flags no macro in an OLE2 file. Content no processor claims is read as text, whatever its name, when its first 4096 bytes hold -no control byte (a C0 control other than tab, line feed, form feed, or carriage return, or DEL) and -are valid UTF-8, a rune cut off at the 4096th byte allowed, or windows-1252 -without its five undefined bytes (0x81, 0x8D, 0x8F, 0x90, 0x9D); otherwise it is unrouted. So HTML -and an EPUB's entries are read as raw text, with no structure, and UTF-16 without a byte order mark, -which holds NULs, and a log holding terminal escapes are refused. docproc detects no -text's encoding: it reads text by its byte order mark, as UTF-8, or else as windows-1252, so a -legacy multibyte encoding such as Shift-JIS, EUC-JP, or ISO-2022-JP reads as mojibake. Beyond that, -each stage inherits its tool's limits, as the tools' READMEs -([docproc-ooxml](../tools/ooxml/README.md), [docproc-mail](../tools/mail/README.md), +no control byte and are either valid UTF-8 or windows-1252 without its five undefined bytes (0x81, +0x8D, 0x8F, 0x90, 0x9D), and is unrouted otherwise. A control byte is a C0 control other than tab, +line feed, form feed, or carriage return, or DEL. A UTF-8 rune cut off at the 4096th byte is allowed +when the content runs past it. So HTML and an EPUB's entries are read as raw text, with no +structure, while UTF-16 without a byte order mark, which holds NULs, and a log holding terminal +escapes are refused. docproc detects no text's encoding: it reads text by its byte order mark, as +UTF-8, or else as windows-1252, so a legacy multibyte encoding such as Shift-JIS, EUC-JP, or +ISO-2022-JP reads as mojibake. Beyond that, each stage inherits its tool's limits, as the tools' +READMEs ([docproc-ooxml](../tools/ooxml/README.md), [docproc-mail](../tools/mail/README.md), [docproc-onenote](../tools/onenote/README.md)) state them in full; these are the ones a host sizes or routes by. diff --git a/route/doc.go b/route/doc.go index 0e627ac..dae95d5 100644 --- a/route/doc.go +++ b/route/doc.go @@ -34,10 +34,11 @@ // whole for an EncryptedPackage stream's directory entry, by [EncryptedPackage], which inspect // calls too; an mbox is read past its "From " line for a message's header; and content of no // signature is read for a message's header, a header after a UTF-8 byte order mark among them. -// A head is text when it holds no control byte, a C0 control other than tab, line feed, form -// feed, or carriage return, or DEL, and is either valid UTF-8 or windows-1252 without its five -// undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D; a rune the head cuts off at its end is valid when the content runs past the head. A byte -// order mark makes content text ahead of the test, so UTF-16 and UTF-32 marked by one are text. +// A head is text when it holds no C0 control other than tab, line feed, form feed, or carriage +// return, and no DEL, and is either valid UTF-8 or windows-1252 without its five undefined bytes, +// 0x81, 0x8D, 0x8F, 0x90, and 0x9D; a rune the head cuts off at its end is valid when the content +// runs past the head. A byte order mark makes content text ahead of the test, so UTF-16 and UTF-32 +// marked by one are text. // The routes: // // - [Document]: a PDF, for the document package's stage. diff --git a/route/media.go b/route/media.go index 661985e..787aead 100644 --- a/route/media.go +++ b/route/media.go @@ -114,7 +114,7 @@ const outlookType = "application/vnd.ms-outlook" // hevx; image/heif for heif, mif1, or miaf; and image/heif-sequence for msf1. Content of no // signature takes the route At gives it, with name and mimeType: message/rfc822 for [Nested]; // application/octet-stream for any route but [Text], whatever its name; and, for Text, a type by -// name's extension, text/markdown for .md or .markdown, text/csv for .csv, +// the name's extension, text/markdown for .md or .markdown, text/csv for .csv, // text/tab-separated-values for .tsv, text/html for .html or .htm, application/xml for .xml, // application/json for .json, application/yaml for .yaml or .yml, text/css for .css, // text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf, or text/plain diff --git a/route/route.go b/route/route.go index 5e47de5..26a8365 100644 --- a/route/route.go +++ b/route/route.go @@ -72,10 +72,10 @@ const ( // "From " line without a message header`, or "no routed signature"; for content named .eml or // stored as a message whose header isn't a message's shape, it is "a message by its , but not header-shaped; text by its head". A name's extension never makes content - // text. A head is text when it holds no control byte, a C0 control other than tab, line feed, - // form feed, or carriage return, or DEL, and is either valid UTF-8 or windows-1252 without - // its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. A rune the head cuts off at its - // end is valid when the content runs past the head, and invalid when the content ends there. + // text. A head is text when it holds no C0 control other than tab, line feed, form feed, or + // carriage return, and no DEL, and is either valid UTF-8 or windows-1252 without its five + // undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and 0x9D. A rune the head cuts off at its end is + // valid when the content runs past the head, and invalid when the content ends there. Text Route = "text" // Unrouted is a deliberate refusal: an executable, by a PE, ELF, or Mach-O signature; an XPS // package, a ZIP holding a FixedDocumentSequence.fdseq entry, whole or as its first piece, @@ -84,7 +84,7 @@ const ( // no other route claims, or that fails a claim's own check, such as an OLE2 compound file // without a legacy or .msg extension, nor an encrypted OOXML package's stream and name, or an // mbox's "From " line without a message header, whose first [HeadLen] bytes aren't text, as - // [Text] reads them: a control byte, or bytes neither UTF-8 nor windows-1252 reads. + // [Text] reads them: a control byte, or bytes that neither UTF-8 nor windows-1252 reads. // Its reason then ends ", not text" and begins with the claim it failed, or "no routed // signature"; for content named .eml or stored as a message whose header isn't a message's // shape, it is "a message by its , but not header-shaped".