Skip to content

Commit

Permalink
fix(manager/dockerfile): remove bom marker (#30156)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Jul 13, 2024
1 parent abfa85a commit 198de58
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/modules/manager/dockerfile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,26 @@ describe('modules/manager/dockerfile/extract', () => {
]);
});

it('extracts tags from Dockerfile which begins with a BOM marker', () => {
const res = extractPackageFile(
'\uFEFFFROM node:6.12.3 as frontend\n\n',
'',
{},
)?.deps;
expect(res).toEqual([
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: '6.12.3',
datasource: 'docker',
depName: 'node',
depType: 'final',
replaceString: 'node:6.12.3',
},
]);
});

it('skips scratches', () => {
const res = extractPackageFile('FROM scratch\nADD foo\n', '', {});
expect(res).toBeNull();
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/dockerfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export function extractPackageFile(
_packageFile: string,
config: ExtractConfig,
): PackageFileContent | null {
const sanitizedContent = content.replace(regEx(/^\uFEFF/), ''); // remove bom marker
const deps: PackageDependency[] = [];
const stageNames: string[] = [];
const args: Record<string, string> = {};
Expand All @@ -253,8 +254,8 @@ export function extractPackageFile(
let lookForEscapeChar = true;
let lookForSyntaxDirective = true;

const lineFeed = content.indexOf('\r\n') >= 0 ? '\r\n' : '\n';
const lines = content.split(newlineRegex);
const lineFeed = sanitizedContent.indexOf('\r\n') >= 0 ? '\r\n' : '\n';
const lines = sanitizedContent.split(newlineRegex);
for (let lineNumber = 0; lineNumber < lines.length; ) {
const lineNumberInstrStart = lineNumber;
let instruction = lines[lineNumber];
Expand Down

0 comments on commit 198de58

Please sign in to comment.