Skip to content
Snippets Groups Projects
Unverified Commit c12c57b2 authored by Sebastian Poxhofer's avatar Sebastian Poxhofer Committed by GitHub
Browse files

fix(managers/pep621): correctly parse extras with whitespace (#33378)

parent 73b842fe
No related branches found
Tags 39.90.1
No related merge requests found
...@@ -4,17 +4,18 @@ import { parsePEP508 } from './utils'; ...@@ -4,17 +4,18 @@ import { parsePEP508 } from './utils';
describe('modules/manager/pep621/utils', () => { describe('modules/manager/pep621/utils', () => {
describe('parsePEP508()', () => { describe('parsePEP508()', () => {
it.each` it.each`
value | success | packageName | currentValue | extras | marker value | success | packageName | currentValue | extras | marker
${''} | ${false} | ${undefined} | ${undefined} | ${undefined} | ${undefined} ${''} | ${false} | ${undefined} | ${undefined} | ${undefined} | ${undefined}
${undefined} | ${false} | ${undefined} | ${undefined} | ${undefined} | ${undefined} ${undefined} | ${false} | ${undefined} | ${undefined} | ${undefined} | ${undefined}
${null} | ${false} | ${undefined} | ${undefined} | ${undefined} | ${undefined} ${null} | ${false} | ${undefined} | ${undefined} | ${undefined} | ${undefined}
${'blinker'} | ${true} | ${'blinker'} | ${undefined} | ${undefined} | ${undefined} ${'blinker'} | ${true} | ${'blinker'} | ${undefined} | ${undefined} | ${undefined}
${'packaging==20.0.0'} | ${true} | ${'packaging'} | ${'==20.0.0'} | ${undefined} | ${undefined} ${'packaging==20.0.0'} | ${true} | ${'packaging'} | ${'==20.0.0'} | ${undefined} | ${undefined}
${'packaging>=20.9,!=22.0'} | ${true} | ${'packaging'} | ${'>=20.9,!=22.0'} | ${undefined} | ${undefined} ${'packaging>=20.9,!=22.0'} | ${true} | ${'packaging'} | ${'>=20.9,!=22.0'} | ${undefined} | ${undefined}
${'cachecontrol[filecache]>=0.12.11'} | ${true} | ${'cachecontrol'} | ${'>=0.12.11'} | ${['filecache']} | ${undefined} ${'cachecontrol[filecache]>=0.12.11'} | ${true} | ${'cachecontrol'} | ${'>=0.12.11'} | ${['filecache']} | ${undefined}
${'tomli>=1.1.0; python_version < "3.11"'} | ${true} | ${'tomli'} | ${'>=1.1.0'} | ${undefined} | ${'python_version < "3.11"'} ${'private-depB[extra1, extra2]~=2.4'} | ${true} | ${'private-depB'} | ${'~=2.4'} | ${['extra1', 'extra2']} | ${undefined}
${'typing-extensions; python_version < "3.8"'} | ${true} | ${'typing-extensions'} | ${undefined} | ${undefined} | ${'python_version < "3.8"'} ${'tomli>=1.1.0; python_version < "3.11"'} | ${true} | ${'tomli'} | ${'>=1.1.0'} | ${undefined} | ${'python_version < "3.11"'}
${'typing-extensions[test-feature]; python_version < "3.8"'} | ${true} | ${'typing-extensions'} | ${undefined} | ${['test-feature']} | ${'python_version < "3.8"'} ${'typing-extensions; python_version < "3.8"'} | ${true} | ${'typing-extensions'} | ${undefined} | ${undefined} | ${'python_version < "3.8"'}
${'typing-extensions[test-feature]; python_version < "3.8"'} | ${true} | ${'typing-extensions'} | ${undefined} | ${['test-feature']} | ${'python_version < "3.8"'}
`( `(
'(parse $value"', '(parse $value"',
({ value, success, packageName, currentValue, extras, marker }) => { ({ value, success, packageName, currentValue, extras, marker }) => {
......
...@@ -10,7 +10,7 @@ import { PyProjectSchema } from './schema'; ...@@ -10,7 +10,7 @@ import { PyProjectSchema } from './schema';
import type { Pep508ParseResult, Pep621ManagerData } from './types'; import type { Pep508ParseResult, Pep621ManagerData } from './types';
const pep508Regex = regEx( const pep508Regex = regEx(
/^(?<packageName>[A-Z0-9._-]+)\s*(\[(?<extras>[A-Z0-9,._-]+)\])?\s*(?<currentValue>[^;]+)?(;\s*(?<marker>.*))?/i, /^(?<packageName>[A-Z0-9._-]+)\s*(\[(?<extras>[A-Z0-9\s,._-]+)\])?\s*(?<currentValue>[^;]+)?(;\s*(?<marker>.*))?/i,
); );
export const depTypes = { export const depTypes = {
...@@ -49,7 +49,8 @@ export function parsePEP508( ...@@ -49,7 +49,8 @@ export function parsePEP508(
result.marker = regExpExec.groups.marker; result.marker = regExpExec.groups.marker;
} }
if (is.nonEmptyString(regExpExec.groups.extras)) { if (is.nonEmptyString(regExpExec.groups.extras)) {
result.extras = regExpExec.groups.extras.split(','); // trim to remove allowed whitespace between brackets
result.extras = regExpExec.groups.extras.split(',').map((e) => e.trim());
} }
return result; return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment