fix(magic_data): detect bash/sh/zsh shell script shebangs as .sh (#150)#151
Open
SAY-5 wants to merge 1 commit into
Open
fix(magic_data): detect bash/sh/zsh shell script shebangs as .sh (#150)#151SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
…riffith#150) Signed-off-by: SAY-5 <say.apm35@gmail.com>
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.
Summary
Fixes #150.
magic_data.jsonhad Python and PowerShell shebang patterns but no entries for the much more common Unix shell shebangs, so a file starting with#!/bin/bashwas matched only by the genericascii textfallback and reported as.txt/text/plain. The reporter hit this on a real.shfile with v2.1.1.Change
puremagic/magic_data.json, add hex-encoded shebang patterns for the standard shells:#!/bin/sh,#! /bin/sh,#!/usr/bin/sh,#!/usr/bin/env sh\n→.sh/application/x-sh#!/bin/bash,#! /bin/bash,#!/usr/bin/bash,#!/usr/bin/env bash,#!/usr/local/bin/bash→.sh/application/x-shellscript#!/bin/zsh,#!/usr/bin/zsh,#!/usr/bin/env zsh\n→.sh/application/x-shellscript#!/bin/dash→.sh/application/x-shThe newline-terminated entries (
env sh\n,env zsh\n) avoid an over-match whereenv shelletc. could collide.Test plan
pytest test/, 96 passed (was 95; +1 new test)test_bash_shebang_detectedcovers#!/bin/bash,#!/bin/sh,#!/usr/bin/env bash,#!/bin/zsh, all return.shtest_small_stream_errorfor the python shebang still passes, python entries are unchanged