fix(pypi): trim simple repo markup with extra whitespaces and new lines (#27013)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
Maksym Romanowski 2024-02-02 11:15:28 +01:00 committed by GitHub
parent 649fb78e48
commit a025178e71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Links for package with extra whitespaces </title>
</head>
<body>
<h1> Links for package with extra whitespaces </h1>
<a href="">
package_with_whitespaces-2.0.0.tar.gz
</a><br>
<a href=""> package_with_whitespaces-2.0.1-py3-none-any.whl </a><br>
<a href=""> package_with_whitespaces-2.0.2-py3-none-any.whl</a><br>
<a href="">package_with_whitespaces-2.0.2.tar.gz </a><br>
</body></html>

View file

@ -14,6 +14,9 @@ const dataRequiresPythonResponse = Fixtures.get(
const mixedHyphensResponse = Fixtures.get('versions-html-mixed-hyphens.html'); const mixedHyphensResponse = Fixtures.get('versions-html-mixed-hyphens.html');
const mixedCaseResponse = Fixtures.get('versions-html-mixed-case.html'); const mixedCaseResponse = Fixtures.get('versions-html-mixed-case.html');
const withPeriodsResponse = Fixtures.get('versions-html-with-periods.html'); const withPeriodsResponse = Fixtures.get('versions-html-with-periods.html');
const withWhitespacesResponse = Fixtures.get(
'versions-html-with-whitespaces.html',
);
const hyphensResponse = Fixtures.get('versions-html-hyphens.html'); const hyphensResponse = Fixtures.get('versions-html-hyphens.html');
const baseUrl = 'https://pypi.org/pypi'; const baseUrl = 'https://pypi.org/pypi';
@ -430,6 +433,26 @@ describe('modules/datasource/pypi/index', () => {
]); ]);
}); });
it('process data from simple endpoint with extra whitespaces in html', async () => {
httpMock
.scope('https://some.registry.org/simple/')
.get('/package-with-whitespaces/')
.reply(200, withWhitespacesResponse);
const config = {
registryUrls: ['https://some.registry.org/simple/'],
};
const res = await getPkgReleases({
datasource,
...config,
packageName: 'package-with-whitespaces',
});
expect(res?.releases).toMatchObject([
{ version: '2.0.0' },
{ version: '2.0.1' },
{ version: '2.0.2' },
]);
});
it('returns null for empty response', async () => { it('returns null for empty response', async () => {
httpMock httpMock
.scope('https://some.registry.org/simple/') .scope('https://some.registry.org/simple/')

View file

@ -246,7 +246,7 @@ export class PypiDatasource extends Datasource {
const releases: Releases = {}; const releases: Releases = {};
for (const link of Array.from(links)) { for (const link of Array.from(links)) {
const version = PypiDatasource.extractVersionFromLinkText( const version = PypiDatasource.extractVersionFromLinkText(
link.text, link.text?.trim(),
packageName, packageName,
); );
if (version) { if (version) {