Skip to content

Commit 4fa8277

Browse files
authored
fix(utils): limit characters of env overrides to context (#585)
1 parent a126b09 commit 4fa8277

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/utils/src/build-context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function getCommitMessage(hash = 'HEAD') {
200200
// GitLab CI
201201
'CI_COMMIT_MESSAGE',
202202
]);
203-
if (envHash) return envHash;
203+
if (envHash) return envHash.trim().slice(0, 80);
204204

205205
const result = childProcess.spawnSync('git', ['log', '--format=%s', '-n', '1', hash], {
206206
encoding: 'utf8',
@@ -226,7 +226,7 @@ function getAuthor(hash = 'HEAD') {
226226
// GitLab CI: https://gitlab.com/gitlab-org/gitlab/-/issues/284079
227227
'CI_COMMIT_AUTHOR',
228228
]);
229-
if (envHash) return envHash;
229+
if (envHash) return envHash.trim().slice(0, 256);
230230

231231
const result = childProcess.spawnSync('git', ['log', '--format=%aN <%aE>', '-n', '1', hash], {
232232
encoding: 'utf8',

packages/utils/test/build-context.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ describe('build-context.js', () => {
8686
process.env.LHCI_BUILD_CONTEXT__COMMIT_MESSAGE = 'Daily run';
8787
expect(buildContext.getCommitMessage(hash)).toEqual('Daily run');
8888
});
89+
90+
it('should limit the message to 80 characters', () => {
91+
process.env.LHCI_BUILD_CONTEXT__COMMIT_MESSAGE = 'a'.repeat(1000);
92+
expect(buildContext.getCommitMessage(hash)).toEqual('a'.repeat(80));
93+
});
8994
});
9095

9196
describe('#getAuthor()', () => {
@@ -97,6 +102,11 @@ describe('build-context.js', () => {
97102
process.env.LHCI_BUILD_CONTEXT__AUTHOR = 'Paul Irish <[email protected]>';
98103
expect(buildContext.getAuthor(hash)).toEqual('Paul Irish <[email protected]>');
99104
});
105+
106+
it('should limit the message to 256 characters', () => {
107+
process.env.LHCI_BUILD_CONTEXT__AUTHOR = 'a'.repeat(1000);
108+
expect(buildContext.getAuthor(hash)).toEqual('a'.repeat(256));
109+
});
100110
});
101111

102112
describe('#getEmailFromAuthor', () => {

0 commit comments

Comments
 (0)