Fix Config.from_file() silent mode not handling ENOTDIR
`Config.from_file()` with `silent=True` did not handle `errno.ENOTDIR`, causing it to raise an error when a path component is a regular file instead of a directory. This was inconsistent with `Config.from_pyfile()`, which has handled ENOTDIR since PR #2581. fixes #5912 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d3b78fd18a
commit
c8ecf241e3
3 changed files with 26 additions and 1 deletions
|
|
@ -195,6 +195,28 @@ def test_config_missing_file():
|
|||
assert not app.config.from_file("missing.json", load=json.load, silent=True)
|
||||
|
||||
|
||||
def test_config_enotdir_from_pyfile(tmp_path):
|
||||
"""from_pyfile with silent=True handles ENOTDIR when a path
|
||||
component is a regular file rather than a directory."""
|
||||
# Create a regular file that will block directory traversal.
|
||||
blocker = tmp_path / "not_a_dir"
|
||||
blocker.write_text("x")
|
||||
app = flask.Flask(__name__)
|
||||
# Trying to open "not_a_dir/settings.cfg" raises ENOTDIR.
|
||||
assert not app.config.from_pyfile(str(blocker / "settings.cfg"), silent=True)
|
||||
|
||||
|
||||
def test_config_enotdir_from_file(tmp_path):
|
||||
"""from_file with silent=True handles ENOTDIR when a path
|
||||
component is a regular file rather than a directory."""
|
||||
blocker = tmp_path / "not_a_dir"
|
||||
blocker.write_text("x")
|
||||
app = flask.Flask(__name__)
|
||||
assert not app.config.from_file(
|
||||
str(blocker / "config.json"), load=json.load, silent=True
|
||||
)
|
||||
|
||||
|
||||
def test_custom_config_class():
|
||||
class Config(flask.Config):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue