Skip to content

Commit

Permalink
fix(github): compare repo names lower case (#19411)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
rarkins and viceice committed Dec 20, 2022
1 parent fc37657 commit a0fe269
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/modules/platform/github/index.ts
Expand Up @@ -34,7 +34,7 @@ import * as hostRules from '../../../util/host-rules';
import * as githubHttp from '../../../util/http/github';
import { regEx } from '../../../util/regex';
import { sanitize } from '../../../util/sanitize';
import { fromBase64 } from '../../../util/string';
import { fromBase64, looseEquals } from '../../../util/string';
import { ensureTrailingSlash } from '../../../util/url';
import type {
AggregatedVulnerabilities,
Expand Down Expand Up @@ -719,7 +719,7 @@ export async function findPr({
return false;
}

if (!config.forkToken && config.repository !== p.sourceRepo) {
if (!config.forkToken && !looseEquals(config.repository, p.sourceRepo)) {
return false;
}

Expand Down
10 changes: 9 additions & 1 deletion lib/util/string.spec.ts
@@ -1,4 +1,4 @@
import { replaceAt } from './string';
import { looseEquals, replaceAt } from './string';

describe('util/string', () => {
describe('replaceAt', () => {
Expand All @@ -24,4 +24,12 @@ describe('util/string', () => {
expect(newContent).toBe('I want to have a new pet maybe a dog');
});
});

describe('looseEquals', () => {
test('reverts to literal match if either is falsey', () => {
expect(looseEquals(undefined, null)).toBeFalse();
expect(looseEquals(null, null)).toBeTrue();
expect(looseEquals(null, '')).toBeFalse();
});
});
});
10 changes: 10 additions & 0 deletions lib/util/string.ts
Expand Up @@ -45,3 +45,13 @@ export function uniqueStrings(
): boolean {
return elements.indexOf(element) === index;
}

export function looseEquals(
a: string | null | undefined,
b: string | null | undefined
): boolean {
if (!(a && b)) {
return a === b;
}
return a.localeCompare(b, undefined, { sensitivity: 'base' }) === 0;
}

0 comments on commit a0fe269

Please sign in to comment.