python / python/cpython

glob.translate incorrectly treats ***

オープン
#131,478 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

While I could not find relevant manpage or other Unix standard, gitignore states:

Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning:

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.

A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.

Other consecutive asterisks are considered regular asterisks and will match according to the previous rules.

My understanding of the last sentence is that a triple asterisk *** (and any longer) should be treated exactly the same as a single one *, but it is not the case. While close, and definitely neither a double asterisk nor a naive repetition of a single one, it has an incorrect quantifier. It is likely caused because the first * is neither surrounded by path separators, nor by string begin/end.

import glob;
print(glob.translate('*', include_hidden=True, recursive=True))
print(glob.translate('***', include_hidden=True, recursive=True))

Expected behavior:

(?s:[^/]+)\Z
(?s:[^/]+)\Z

Actual behavior:

(?s:[^/]+)\Z
(?s:[^/]*)\Z
CPython versions tested on:

3.13

Operating systems tested on:

Linux

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されている glob.translate の例を実行し、glob.translate のエントリーポイントを調べます。再帰的マッチングにおける '' と '**' の扱いを比較し、期待される同一の正規表現に対するカバレッジを追加してから、Python 3.13 で報告された動作を検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。