From abea35d5c6ed0035fb6326f167d0dc57d512f297 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Thu, 30 Apr 2026 00:55:18 -0700 Subject: [PATCH] fix(magic_data): detect bash/sh/zsh shell script shebangs as .sh (#150) Signed-off-by: SAY-5 --- puremagic/magic_data.json | 13 +++++++++++++ test/test_common_extensions.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/puremagic/magic_data.json b/puremagic/magic_data.json index 5a051d4..1db870f 100644 --- a/puremagic/magic_data.json +++ b/puremagic/magic_data.json @@ -903,6 +903,19 @@ ["23212f7573722f6c6f63616c2f62696e2f707974686f6e", 0, ".wsgi", "text/x-python", "Python script"], ["2321202f7573722f6c6f63616c2f62696e2f707974686f6e", 0, ".wsgi", "text/x-python", "Python script"], ["6576616c205c2265786563202f7573722f6c6f63616c2f62696e2f707974686f6e", 0, ".wsgi", "text/x-python", "Python script"], + ["23212f62696e2f7368", 0, ".sh", "application/x-sh", "POSIX shell script"], + ["2321202f62696e2f7368", 0, ".sh", "application/x-sh", "POSIX shell script"], + ["23212f7573722f62696e2f7368", 0, ".sh", "application/x-sh", "POSIX shell script"], + ["23212f7573722f62696e2f656e762073680a", 0, ".sh", "application/x-sh", "POSIX shell script"], + ["23212f62696e2f64617368", 0, ".sh", "application/x-sh", "Dash shell script"], + ["23212f62696e2f62617368", 0, ".sh", "application/x-shellscript", "Bash shell script"], + ["2321202f62696e2f62617368", 0, ".sh", "application/x-shellscript", "Bash shell script"], + ["23212f7573722f62696e2f62617368", 0, ".sh", "application/x-shellscript", "Bash shell script"], + ["23212f7573722f62696e2f656e762062617368", 0, ".sh", "application/x-shellscript", "Bash shell script"], + ["23212f7573722f6c6f63616c2f62696e2f62617368", 0, ".sh", "application/x-shellscript", "Bash shell script"], + ["23212f62696e2f7a7368", 0, ".sh", "application/x-shellscript", "Zsh shell script"], + ["23212f7573722f62696e2f7a7368", 0, ".sh", "application/x-shellscript", "Zsh shell script"], + ["23212f7573722f62696e2f656e76207a73680a", 0, ".sh", "application/x-shellscript", "Zsh shell script"], ["53756d6d6172793a20", 0, ".spec", "text/x-rpm-spec", "RPM spec file"], ["25646566696e6520", 0, ".spec", "text/x-rpm-spec", "RPM spec file"], ["667479707174", 4, ".qtvr", "video/quicktime", "QuickTime video"], diff --git a/test/test_common_extensions.py b/test/test_common_extensions.py index 0294b2b..c65e8e4 100644 --- a/test/test_common_extensions.py +++ b/test/test_common_extensions.py @@ -291,3 +291,15 @@ def test_cfbf_msg(): assert ext == ".msg" mime = puremagic.from_file(os.path.join(OFFICE_DIR, "test.msg"), mime=True) assert mime == "application/vnd.ms-outlook" + + +def test_bash_shebang_detected(): + """Regression for #150: shell script shebangs identify as .sh, not .txt.""" + bash = puremagic.from_stream(BytesIO(b"#!/bin/bash\necho hi\n")) + assert bash == ".sh" + sh = puremagic.from_stream(BytesIO(b"#!/bin/sh\necho hi\n")) + assert sh == ".sh" + env_bash = puremagic.from_stream(BytesIO(b"#!/usr/bin/env bash\necho hi\n")) + assert env_bash == ".sh" + zsh = puremagic.from_stream(BytesIO(b"#!/bin/zsh\necho hi\n")) + assert zsh == ".sh"