Skip to content

Commit 8609c49

Browse files
committed
fix(getos): fix OSRegex "id" & "id_like" including ending quotes
re #525
1 parent 197281d commit 8609c49

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/mongodb-memory-server-core/src/util/getos/__tests__/getos.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,28 @@ UBUNTU_CODENAME=focal`;
6262
id_like: 'ubuntu',
6363
});
6464
});
65+
66+
it('should parse an full os-release file with quotes', () => {
67+
const example = `NAME="Linux Mint"
68+
VERSION="20.2 (Uma)"
69+
ID="linuxmint"
70+
ID_LIKE="ubuntu"
71+
PRETTY_NAME="Linux Mint 20.2"
72+
VERSION_ID="20.2"
73+
HOME_URL="https://www.linuxmint.com/"
74+
SUPPORT_URL="https://forums.linuxmint.com/"
75+
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
76+
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
77+
VERSION_CODENAME=uma
78+
UBUNTU_CODENAME=focal`;
79+
80+
expect(getos.parseOS(example)).toEqual<getos.LinuxOS>({
81+
os: 'linux',
82+
dist: 'linuxmint',
83+
release: '20.2',
84+
codename: 'uma',
85+
id_like: 'ubuntu',
86+
});
87+
});
6588
});
6689
});

packages/mongodb-memory-server-core/src/util/getos/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const LSBRegex = {
1414

1515
/** Collection of Regexes for "/etc/os-release" parsing */
1616
const OSRegex = {
17-
name: /^id\s*=\s*"?(.*)"?$/im,
17+
name: /^id\s*=\s*"?(\w*)"?$/im,
1818
codename: /^version_codename\s*=\s*(.*)$/im,
1919
release: /^version_id\s*=\s*"?(\d*(?:\.\d*)?)"?$/im,
20-
id_like: /^id_like\s*=\s*"?(.*)"?$/im,
20+
id_like: /^id_like\s*=\s*"?(\w*)"?$/im,
2121
};
2222

2323
export interface OtherOS {

0 commit comments

Comments
 (0)