diff --git a/python_json_config/__version__.py b/python_json_config/__version__.py
index c68196d..a955fda 100644
--- a/python_json_config/__version__.py
+++ b/python_json_config/__version__.py
@@ -1,1 +1,1 @@
-__version__ = "1.2.0"
+__version__ = "1.2.1"
diff --git a/python_json_config/config_node.py b/python_json_config/config_node.py
index 9fb07b3..07a8d04 100644
--- a/python_json_config/config_node.py
+++ b/python_json_config/config_node.py
@@ -144,11 +144,9 @@ class ConfigNode(object):
         prefixes = [prefix] if isinstance(prefix, str) else prefix
         for key in os.environ:
             for prefix in prefixes:
-                if key.startswith(prefix):
+                if key.startswith(f"{prefix}_"):
                     value = os.environ[key]
-                    cleaned_key = key[len(prefix):]
-                    if cleaned_key[0] == "_":
-                        cleaned_key = cleaned_key[1:]
+                    cleaned_key = key[len(prefix) + 1:]
                     cleaned_key = cleaned_key.lower().split("_")
                     self.update(path=cleaned_key, value=value, upsert=True)
 

Environment variable prefix should only match those variables with an underscore after the prefix
E.g. with prefix `TEST` the following should happen
- match `TEST_VALUE`
- not match `TESTSUITE_VERSION`

Currently it matches both
diff --git a/tests/config_builder_test.py b/tests/config_builder_test.py
index 6a6030d..e01fa54 100644
--- a/tests/config_builder_test.py
+++ b/tests/config_builder_test.py
@@ -1,5 +1,4 @@
 import json
-import os
 
 import pytest
 from jsonschema import ValidationError
@@ -168,21 +167,15 @@ def test_optional_validation(path):
 
 
 def test_merge_env_variable():
-    prefix = "PYTHONJSONCONFIG"
-    variables = {f"{prefix}_TESTVALUE1": "bla", f"{prefix}_TESTVALUE2": "1"}
-    for key, value in variables.items():
-        os.environ[key] = value
-
+    prefix1 = "PYTHONJSONCONFIG"
+    prefixes2 = ["PREFIX1", "PREFIX2"]
     builder = ConfigBuilder()
-    builder.merge_with_env_variables(prefix)
-    config = builder.parse_config({"testvalue1": "blub", "testvalue3": 5})
 
-    assert config.testvalue1 == "bla"
-    assert config.testvalue2 == "1"
-    assert config.testvalue3 == 5
+    builder.merge_with_env_variables(prefix1)
+    assert builder._ConfigBuilder__environment_variable_prefixes == [prefix1]
 
-    for key, value in variables.items():
-        del os.environ[key]
+    builder.merge_with_env_variables(prefixes2)
+    assert builder._ConfigBuilder__environment_variable_prefixes == [prefix1] + prefixes2
 
 
 def test_build_from_serialized_config(path):
diff --git a/tests/config_node/test_crud.py b/tests/config_node/test_crud.py
index 503e4c1..16737a7 100644
--- a/tests/config_node/test_crud.py
+++ b/tests/config_node/test_crud.py
@@ -142,12 +142,16 @@ def test_merge_env_variable():
     for key, value in variables.items():
         os.environ[key] = value
 
+    invalid_prefix = "PYTHONJSONCONFIGTEST"
+    os.environ[invalid_prefix] = "invalid"
+
     config = ConfigNode({"testvalue1": "blub", "testvalue3": 5})
     config.merge_with_env_variables(prefix)
 
     assert config.testvalue1 == "bla"
     assert config.testvalue2 == "1"
     assert config.testvalue3 == 5
+    assert "test" not in config
 
     for key, value in variables.items():
         del os.environ[key]

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio pytest-bdd pytest-benchmark pytest-randomly
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
atomicwrites==1.3.0
attrs==19.1.0
coverage==7.8.0
entrypoints==0.3
exceptiongroup==1.2.2
execnet==2.1.1
flake8==3.7.7
flake8-formatter-abspath==1.0.1
gherkin-official==29.0.0
importlib_metadata==8.6.1
iniconfig==2.1.0
jsonschema==3.0.1
Mako==1.3.9
MarkupSafe==3.0.2
mccabe==0.6.1
more-itertools==7.0.0
msgpack==0.6.1
packaging==24.2
parse==1.20.2
parse_type==0.6.4
pluggy==1.5.0
py==1.8.0
py-cpuinfo==9.0.0
pycodestyle==2.5.0
pyflakes==2.1.1
pyrsistent==0.14.11
pytest==8.3.5
pytest-asyncio==0.26.0
pytest-bdd==8.1.0
pytest-benchmark==5.1.0
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
pytest-xdist==3.6.1
-e git+https://github.com/janehmueller/python-json-config.git@b1cf8cf5b3882d6a80881433cb692857afe948f6#egg=python_json_config
six==1.17.0
tomli==2.2.1
typing_extensions==4.13.0
zipp==3.21.0

name: python-json-config
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - atomicwrites==1.3.0
      - attrs==19.1.0
      - coverage==7.8.0
      - entrypoints==0.3
      - exceptiongroup==1.2.2
      - execnet==2.1.1
      - flake8==3.7.7
      - flake8-formatter-abspath==1.0.1
      - gherkin-official==29.0.0
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - jsonschema==3.0.1
      - mako==1.3.9
      - markupsafe==3.0.2
      - mccabe==0.6.1
      - more-itertools==7.0.0
      - msgpack==0.6.1
      - packaging==24.2
      - parse==1.20.2
      - parse-type==0.6.4
      - pluggy==1.5.0
      - py==1.8.0
      - py-cpuinfo==9.0.0
      - pycodestyle==2.5.0
      - pyflakes==2.1.1
      - pyrsistent==0.14.11
      - pytest==8.3.5
      - pytest-asyncio==0.26.0
      - pytest-bdd==8.1.0
      - pytest-benchmark==5.1.0
      - pytest-cov==6.0.0
      - pytest-mock==3.14.0
      - pytest-randomly==3.16.0
      - pytest-xdist==3.6.1
      - six==1.17.0
      - tomli==2.2.1
      - typing-extensions==4.13.0
      - zipp==3.21.0
prefix: /opt/conda/envs/python-json-config

tests/config_node/test_crud.py::test_merge_env_variable
tests/config_builder_test.py::test_value_transformation_builder tests/config_builder_test.py::test_required_access tests/config_builder_test.py::test_merge_env_variable tests/config_builder_test.py::test_value_transformation tests/config_builder_test.py::test_optional_access tests/config_builder_test.py::test_json_schema_validation tests/config_builder_test.py::test_type_validation_builder tests/config_builder_test.py::test_optional_validation tests/config_builder_test.py::test_build_from_serialized_config tests/config_builder_test.py::test_parse tests/config_builder_test.py::test_value_validation_error_messages tests/config_builder_test.py::test_type_validation tests/config_builder_test.py::test_value_validation tests/config_builder_test.py::test_value_validation_builder tests/config_node/test_crud.py::test_strict_access tests/config_node/test_crud.py::test_nested_upsert tests/config_node/test_crud.py::test_add_overwrite tests/config_node/test_crud.py::test_creation tests/config_node/test_crud.py::test_nested_update tests/config_node/test_crud.py::test_get tests/config_node/test_crud.py::test_update tests/config_node/test_crud.py::test_add tests/config_node/test_crud.py::test_upsert
python_json_config/__version__.py python_json_config/config_node.py
python_json_config/__version__.py python_json_config/config_node.py