diff --git a/app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php b/app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php
index b33c944c734774a703816e1ebc6f0ce61fdf3235..7f2f771a8d0a6373bed9dfc7847532ee9a6f5c2f 100644
--- a/app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php
+++ b/app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php
@@ -3,6 +3,7 @@
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
+
 namespace Magento\Config\App\Config\Source;
 
 use Magento\Framework\App\Config\ConfigSourceInterface;
@@ -88,12 +89,12 @@ class RuntimeConfigSource implements ConfigSourceInterface
             }
         }
 
-        foreach ($config as $scope => &$item) {
+        foreach ($config as $scope => $item) {
             if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
-                $item = $this->converter->convert($item);
+                $config[$scope] = $this->converter->convert($item);
             } else {
-                foreach ($item as &$scopeItems) {
-                    $scopeItems = $this->converter->convert($scopeItems);
+                foreach ($item as $scopeCode => $scopeItems) {
+                    $config[$scope][$scopeCode] = $this->converter->convert($scopeItems);
                 }
             }
         }
diff --git a/lib/internal/Magento/Framework/App/Config/Scope/Converter.php b/lib/internal/Magento/Framework/App/Config/Scope/Converter.php
index 7f4a3aead36f532a17b1b8033cf61c644ba0c52b..d8e9469ac398035a0c85f694dc2ae2fc4b24b96d 100644
--- a/lib/internal/Magento/Framework/App/Config/Scope/Converter.php
+++ b/lib/internal/Magento/Framework/App/Config/Scope/Converter.php
@@ -5,6 +5,7 @@
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
+
 namespace Magento\Framework\App\Config\Scope;
 
 class Converter implements \Magento\Framework\Config\ConverterInterface
@@ -19,7 +20,7 @@ class Converter implements \Magento\Framework\Config\ConverterInterface
     {
         $output = [];
         foreach ($source as $key => $value) {
-            $this->_setArrayValue($output, $key, $value);
+            $output = $this->_setArrayValue($output, $key, $value);
         }
         return $output;
     }
@@ -27,21 +28,25 @@ class Converter implements \Magento\Framework\Config\ConverterInterface
     /**
      * Set array value by path
      *
-     * @param array &$container
+     * @param array $container
      * @param string $path
      * @param string $value
-     * @return void
+     * @return array
      */
-    protected function _setArrayValue(array &$container, $path, $value)
+    protected function _setArrayValue(array $container, $path, $value)
     {
-        $segments = explode('/', $path);
-        $currentPointer = & $container;
-        foreach ($segments as $segment) {
-            if (!isset($currentPointer[$segment])) {
-                $currentPointer[$segment] = [];
+        $parts = explode('/', $path);
+        if (count($parts) > 0) {
+            $parts = array_reverse($parts);
+            $result = $value;
+            foreach ($parts as $part) {
+                $part = trim($part);
+                if ($part !== '') {
+                    $result = [$part => $result];
+                }
             }
-            $currentPointer = & $currentPointer[$segment];
+            $container = array_merge_recursive($container, $result);
         }
-        $currentPointer = $value;
+        return $container;
     }
 }
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Config/Scope/ConverterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Config/Scope/ConverterTest.php
index ad449c5852fbb99aa1f14bf96ab19581de0d33cb..283b56fccde2ad90b537534e3a7ed34e349e778e 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/Config/Scope/ConverterTest.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/Config/Scope/ConverterTest.php
@@ -3,6 +3,7 @@
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
+
 namespace Magento\Framework\App\Test\Unit\Config\Scope;
 
 class ConverterTest extends \PHPUnit\Framework\TestCase
@@ -19,8 +20,29 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
 
     public function testConvert()
     {
-        $data = ['some/config/path1' => 'value1', 'some/config/path2' => 'value2'];
-        $expectedResult = ['some' => ['config' => ['path1' => 'value1', 'path2' => 'value2']]];
+        $data = [
+            'some/config/path1' => 'value1',
+            'some/config/path2' => 'value2',
+            'some/config/path2' => 'value3',
+            'some2/config/path2' => 'value4',
+            'some/bad/path////' => 'value5',
+        ];
+        $expectedResult = [
+            'some' => [
+                'config' => [
+                    'path1' => 'value1',
+                    'path2' => 'value3',
+                ],
+                'bad' => [
+                    'path' => 'value5',
+                ],
+            ],
+            'some2' => [
+                'config' => [
+                    'path2' => 'value4',
+                ]
+            ]
+        ];
         $this->assertEquals($expectedResult, $this->_model->convert($data));
     }
 }