Fix file -m/-M options: support hex escapes and correct magic file selection#557
Draft
Fix file -m/-M options: support hex escapes and correct magic file selection#557
Conversation
- Fixed get_magic_files() to only use specified magic file with -m (not default) - Changed Value::String to store Vec<u8> instead of String to handle non-UTF-8 bytes - Implemented hex escape sequence parsing (\xNN) for magic files - Fixed octal escape sequence parsing to work with raw bytes - Updated string_test to compare raw bytes directly - Added test for JBIG2 image detection using hex escape sequences - All existing tests pass Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
- Fix misleading comment about hex value representation - Move test_magic_line_parsing inside mod tests block Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix -m and -M options for file utility
Fix file -m/-M options: support hex escapes and correct magic file selection
Feb 8, 2026
jgarzik
requested changes
Feb 11, 2026
Contributor
jgarzik
left a comment
There was a problem hiding this comment.
this change breaks ci:
test ui::terminal::tests::test_both_env_override ... FAILED
failures:
---- ui::terminal::tests::test_both_env_override stdout ----
thread 'ui::terminal::tests::test_both_env_override' (20992) panicked at editors/vi/ui/terminal.rs:334:13:
assertion `left == right` failed
left: 80
right: 100
stack backtrace:
0: __rustc::rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
4: core::ops::function::FnOnce::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
failures:
ui::terminal::tests::test_both_env_override
test result: FAILED. 177 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
error: test failed, to rerun pass `-p posixutils-editors --lib`
Error: Process completed with exit code 101.
Contributor
Author
The CI failure in I ran the failing test locally and it passes: All 178 tests in posixutils-editors pass, and all 77 tests in posixutils-file pass. This appears to be a flaky test or environment-specific issue in CI, not caused by these changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
-mand-Moptions were non-functional. When-mwas specified, both the custom and default magic files were used instead of just the custom file. Additionally, hex escape sequences (\xNN) in magic files were not parsed, preventing detection of binary formats like JBIG2.Changes
Magic file selection logic
-m filenow uses only the specified file (previously added default as well)-m file -duses both the specified file and default (correct behavior)-Mbehaves identically to-mper POSIX specHex escape sequence support
\xNNparsing for magic file patterns0 string \x97JB2\x0D\x0A\x1A\x0A JBIG2 image datanow worksBinary data handling
Value::StringfromStringtoVec<u8>to support arbitrary byte sequencesStringtype requires valid UTF-8, but magic patterns match raw binary dataExample
Before:
After:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
pubs.opengroup.org/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.