Repository: sharkdp/bat (rust)

Issue:
Case sensitivity inconsistency between --map-syntax and --language command line parameters

**What steps will reproduce the bug?**

1. create a valid todo.txt file http://todotxt.org/ with a custom name, e.g. todo_2025-01.txt
2. run `bat --map-syntax "todo*.txt:todo.txt" todo_2025-01.txt`
3. run `bat --map-syntax "todo*.txt:Todo.txt" todo_2025-01.txt`
4. run `bat --language todo.txt todo_2024-12.txt`

**What happens?**

number 2 will fail with:

    [bat error]: unknown syntax: 'todo.txt'

**What did you expect to happen instead?**

I expected syntax highlighting in the same way that the language flag works.
  * It appears that the language flag is __case insensitive__.
 * It appears that the map-syntax flag is **case sensitive**.

**How did you install `bat`?**

download [msvc zip](https://github.com/sharkdp/bat/releases/download/v0.25.0/bat-v0.25.0-x86_64-pc-windows-msvc.zip) from https://github.com/sharkdp/bat/releases/tag/v0.25.0 extract exe to path.

---

**bat version and environment**

    C:\>bat --version
    bat 0.25.0 (25f4f96)

`C:\>bat  --diagnostic`

#### Software version

bat 0.25.0 (25f4f96)

#### Operating system

Windows 6.2.9200

#### Command-line

```bash
bat --diagnostic
```

#### Environment variables

```bash
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
COLORTERM=<not set>
LANG=<not set>
LC_ALL=<not set>
LESS=<not set>
MANPAGER=<not set>
NO_COLOR=<not set>
PAGER=<not set>
SHELL=<not set>
TERM=<not set>
XDG_CACHE_HOME=<not set>
XDG_CONFIG_HOME=<not set>
```

#### System Config file

Could not read contents of 'C:\ProgramData\bat\config': The system cannot find the path specified. (os error 3).

#### Config file

Could not read contents of 'C:\Users\clach04\AppData\Roaming\bat\config': The system cannot find the path specified. (os error 3).

#### Custom assets metadata

Could not read contents of 'C:\Users\clach04\AppData\Local\bat\metadata.yaml': The system cannot find the path specified. (os error 3).

#### Custom assets

'C:\Users\clach04\AppData\Local\bat' not found

#### Compile time information

- Profile: release
- Target triple: x86_64-pc-windows-msvc
- Family: windows
- OS: windows
- Architecture: x86_64
- Pointer width: 64
- Endian: little
- CPU features: cmpxchg16b,fxsr,sse,sse2,sse3
- Host: x86_64-pc-windows-msvc


Pull request:
Make map-syntax target case insensitive
Fixes #3175

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29ddf751..b56fbf8c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@
 - Fix crash for multibyte characters in file path, see issue #3230 and PR #3245 (@HSM95)
 - Add missing mappings for various bash/zsh files, see PR #3262 (@AdamGaskins)
 - Send all bat errors to stderr by default, see #3336 (@JerryImMouse)
+- Make --map-syntax target case insensitive to match --language, see #3206 (@keith-hall)
 
 ## Other
 
diff --git a/src/assets.rs b/src/assets.rs
index a5608e3b..ed6f27e9 100644
--- a/src/assets.rs
+++ b/src/assets.rs
@@ -163,7 +163,7 @@ impl HighlightingAssets {
 
         if let Some(MappingTarget::MapTo(syntax_name)) = syntax_match {
             return self
-                .find_syntax_by_name(syntax_name)?
+                .find_syntax_by_token(syntax_name)?
                 .ok_or_else(|| Error::UnknownSyntax(syntax_name.to_owned()));
         }
 
@@ -259,6 +259,13 @@ impl HighlightingAssets {
             .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
     }
 
+    fn find_syntax_by_token(&self, token: &str) -> Result<Option<SyntaxReferenceInSet>> {
+        let syntax_set = self.get_syntax_set()?;
+        Ok(syntax_set
+            .find_syntax_by_token(token)
+            .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
+    }
+
     fn get_syntax_for_file_name(
         &self,
         file_name: &OsStr,


Test patch:
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index c367c538..0f570f89 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -2821,6 +2821,27 @@ fn highlighting_independant_from_map_syntax_case() {
         .stderr("");
 }
 
+#[test]
+fn map_syntax_target_syntax_case_insensitive() {
+    let expected = bat()
+        .arg("-f")
+        .arg("--map-syntax=*.config:json")
+        .arg("map-syntax_case.Config")
+        .assert()
+        .get_output()
+        .stdout
+        .clone();
+
+    bat()
+        .arg("-f")
+        .arg("--map-syntax=*.config:json")
+        .arg("map-syntax_case.Config")
+        .assert()
+        .success()
+        .stdout(expected)
+        .stderr("");
+}
+
 #[test]
 fn strip_ansi_always_strips_ansi() {
     bat()