Check whether two file paths refer to the same file. PHPCS may use the `--stdin-path` value as the key. We compare by checking suffix matches (one path ends with the other) to handle cases where one path is relative and the other is absolute, or where symlinks produce different prefixes.
(a: &str, b: &str)
| 346 | /// cases where one path is relative and the other is absolute, or |
| 347 | /// where symlinks produce different prefixes. |
| 348 | fn paths_match(a: &str, b: &str) -> bool { |
| 349 | if a == b { |
| 350 | return true; |
| 351 | } |
| 352 | // Normalize separators for comparison. |
| 353 | let a_norm = a.replace('\\', "/"); |
| 354 | let b_norm = b.replace('\\', "/"); |
| 355 | if a_norm == b_norm { |
| 356 | return true; |
| 357 | } |
| 358 | // Check suffix match (one is a suffix of the other), requiring a |
| 359 | // path separator boundary so that e.g. "AFoo.php" does not match "Foo.php". |
| 360 | a_norm.ends_with(&format!("/{}", b_norm)) || b_norm.ends_with(&format!("/{}", a_norm)) |
| 361 | } |
| 362 | |
| 363 | // ── Helpers ───────────────────────────────────────────────────────── |
| 364 |