@smithy/shared-ini-file-loader 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseIni = void 0;
4
4
  const types_1 = require("@smithy/types");
5
5
  const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles");
6
- const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-]+)\2$/;
6
+ const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@]+)\2$/;
7
7
  const profileNameBlockList = ["__proto__", "profile __proto__"];
8
8
  const parseIni = (iniData) => {
9
9
  const map = {};
10
10
  let currentSection;
11
11
  let currentSubSection;
12
- for (let line of iniData.split(/\r?\n/)) {
13
- line = line.split(/(^|\s)[;#]/)[0].trim();
14
- const isSection = line[0] === "[" && line[line.length - 1] === "]";
12
+ for (const iniLine of iniData.split(/\r?\n/)) {
13
+ const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
14
+ const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
15
15
  if (isSection) {
16
16
  currentSection = undefined;
17
17
  currentSubSection = undefined;
18
- const sectionName = line.substring(1, line.length - 1);
18
+ const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
19
19
  const matches = prefixKeyRegex.exec(sectionName);
20
20
  if (matches) {
21
21
  const [, prefix, , name] = matches;
@@ -31,16 +31,19 @@ const parseIni = (iniData) => {
31
31
  }
32
32
  }
33
33
  else if (currentSection) {
34
- const indexOfEqualsSign = line.indexOf("=");
34
+ const indexOfEqualsSign = trimmedLine.indexOf("=");
35
35
  if (![0, -1].includes(indexOfEqualsSign)) {
36
36
  const [name, value] = [
37
- line.substring(0, indexOfEqualsSign).trim(),
38
- line.substring(indexOfEqualsSign + 1).trim(),
37
+ trimmedLine.substring(0, indexOfEqualsSign).trim(),
38
+ trimmedLine.substring(indexOfEqualsSign + 1).trim(),
39
39
  ];
40
40
  if (value === "") {
41
41
  currentSubSection = name;
42
42
  }
43
43
  else {
44
+ if (currentSubSection && iniLine.trimStart() === iniLine) {
45
+ currentSubSection = undefined;
46
+ }
44
47
  map[currentSection] = map[currentSection] || {};
45
48
  const key = currentSubSection ? [currentSubSection, name].join(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR) : name;
46
49
  map[currentSection][key] = value;
@@ -1,18 +1,18 @@
1
1
  import { IniSectionType } from "@smithy/types";
2
2
  import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
3
- const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-]+)\2$/;
3
+ const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@]+)\2$/;
4
4
  const profileNameBlockList = ["__proto__", "profile __proto__"];
5
5
  export const parseIni = (iniData) => {
6
6
  const map = {};
7
7
  let currentSection;
8
8
  let currentSubSection;
9
- for (let line of iniData.split(/\r?\n/)) {
10
- line = line.split(/(^|\s)[;#]/)[0].trim();
11
- const isSection = line[0] === "[" && line[line.length - 1] === "]";
9
+ for (const iniLine of iniData.split(/\r?\n/)) {
10
+ const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
11
+ const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
12
12
  if (isSection) {
13
13
  currentSection = undefined;
14
14
  currentSubSection = undefined;
15
- const sectionName = line.substring(1, line.length - 1);
15
+ const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
16
16
  const matches = prefixKeyRegex.exec(sectionName);
17
17
  if (matches) {
18
18
  const [, prefix, , name] = matches;
@@ -28,16 +28,19 @@ export const parseIni = (iniData) => {
28
28
  }
29
29
  }
30
30
  else if (currentSection) {
31
- const indexOfEqualsSign = line.indexOf("=");
31
+ const indexOfEqualsSign = trimmedLine.indexOf("=");
32
32
  if (![0, -1].includes(indexOfEqualsSign)) {
33
33
  const [name, value] = [
34
- line.substring(0, indexOfEqualsSign).trim(),
35
- line.substring(indexOfEqualsSign + 1).trim(),
34
+ trimmedLine.substring(0, indexOfEqualsSign).trim(),
35
+ trimmedLine.substring(indexOfEqualsSign + 1).trim(),
36
36
  ];
37
37
  if (value === "") {
38
38
  currentSubSection = name;
39
39
  }
40
40
  else {
41
+ if (currentSubSection && iniLine.trimStart() === iniLine) {
42
+ currentSubSection = undefined;
43
+ }
41
44
  map[currentSection] = map[currentSection] || {};
42
45
  const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
43
46
  map[currentSection][key] = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/shared-ini-file-loader",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "dependencies": {
5
5
  "@smithy/types": "^2.3.5",
6
6
  "tslib": "^2.5.0"