Skip to content

Commit

Permalink
Merge pull request from GHSA-m678-f26j-3hrp
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Oct 19, 2022
1 parent d3f61f3 commit 1118c8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion jupyter_core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def _config_dir_default(self):
def config_file_paths(self):
path = jupyter_config_path()
if self.config_dir not in path:
# Insert config dir as first item.
path.insert(0, self.config_dir)
path.insert(0, os.getcwd())
return path

data_dir = Unicode()
Expand Down
38 changes: 23 additions & 15 deletions jupyter_core/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,51 @@ def test_generate_config():

def test_load_config():
config_dir = mkdtemp()
wd = mkdtemp()
os.environ["JUPYTER_CONFIG_PATH"] = str(config_dir)
with open(pjoin(config_dir, "dummy_app_config.py"), "w", encoding="utf-8") as f:
f.write("c.DummyApp.m = 1\n")
f.write("c.DummyApp.n = 1")
with patch.object(os, "getcwd", lambda: wd):
app = DummyApp(config_dir=config_dir)
app.initialize([])

app = DummyApp(config_dir=config_dir)
app.initialize([])

assert app.n == 1, "Loaded config from config dir"
assert app.m == 1, "Loaded config from config dir"

shutil.rmtree(config_dir)
del os.environ["JUPYTER_CONFIG_PATH"]

with open(pjoin(wd, "dummy_app_config.py"), "w", encoding="utf-8") as f:
f.write("c.DummyApp.n = 2")

def test_load_config_no_cwd():
config_dir = mkdtemp()
wd = mkdtemp()
with open(pjoin(wd, "dummy_app_config.py"), "w", encoding="utf-8") as f:
f.write("c.DummyApp.m = 1\n")
f.write("c.DummyApp.n = 1")
with patch.object(os, "getcwd", lambda: wd):
app = DummyApp(config_dir=config_dir)
app.initialize([])

assert app.m == 1, "Loaded config from config dir"
assert app.n == 2, "Loaded config from CWD"
assert app.n == 0
assert app.m == 0

shutil.rmtree(config_dir)
shutil.rmtree(wd)


def test_load_bad_config():
config_dir = mkdtemp()
wd = mkdtemp()
os.environ["JUPYTER_CONFIG_PATH"] = str(config_dir)
with open(pjoin(config_dir, "dummy_app_config.py"), "w", encoding="utf-8") as f:
f.write('c.DummyApp.m = "a\n') # Syntax error
with patch.object(os, "getcwd", lambda: wd):
with pytest.raises(SyntaxError):
app = DummyApp(config_dir=config_dir)
app.raise_config_file_errors = True
app.initialize([])

with pytest.raises(SyntaxError):
app = DummyApp(config_dir=config_dir)
app.raise_config_file_errors = True
app.initialize([])

shutil.rmtree(config_dir)
shutil.rmtree(wd)
del os.environ["JUPYTER_CONFIG_PATH"]


def test_runtime_dir_changed():
Expand Down

0 comments on commit 1118c8c

Please sign in to comment.