mirror of https://github.com/actions/checkout
Compare commits
2 Commits
4b8779770e
...
130335a4d9
| Author | SHA1 | Date |
|---|---|---|
|
|
130335a4d9 | |
|
|
818b5b3072 |
|
|
@ -492,39 +492,4 @@ describe('git user-agent with orchestration ID', () => {
|
||||||
'git/2.18 (github-actions-checkout)'
|
'git/2.18 (github-actions-checkout)'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not append orchestration ID when it becomes empty after sanitization', async () => {
|
|
||||||
const orchId = '()///'
|
|
||||||
process.env['ACTIONS_ORCHESTRATION_ID'] = orchId
|
|
||||||
|
|
||||||
let capturedEnv: any = null
|
|
||||||
mockExec.mockImplementation((path, args, options) => {
|
|
||||||
if (args.includes('version')) {
|
|
||||||
options.listeners.stdout(Buffer.from('2.18'))
|
|
||||||
}
|
|
||||||
// Capture env on any command
|
|
||||||
capturedEnv = options.env
|
|
||||||
return 0
|
|
||||||
})
|
|
||||||
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
|
|
||||||
|
|
||||||
const workingDirectory = 'test'
|
|
||||||
const lfs = false
|
|
||||||
const doSparseCheckout = false
|
|
||||||
git = await commandManager.createCommandManager(
|
|
||||||
workingDirectory,
|
|
||||||
lfs,
|
|
||||||
doSparseCheckout
|
|
||||||
)
|
|
||||||
|
|
||||||
// Call a git command to trigger env capture after user-agent is set
|
|
||||||
await git.init()
|
|
||||||
|
|
||||||
// Verify the user agent does NOT contain orchestration ID when sanitized ID is empty
|
|
||||||
expect(git).toBeDefined()
|
|
||||||
expect(capturedEnv).toBeDefined()
|
|
||||||
expect(capturedEnv['GIT_HTTP_USER_AGENT']).toBe(
|
|
||||||
'git/2.18 (github-actions-checkout)'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1213,8 +1213,7 @@ class GitCommandManager {
|
||||||
// Sanitize the orchestration ID to ensure it contains only valid characters
|
// Sanitize the orchestration ID to ensure it contains only valid characters
|
||||||
// Valid characters: 0-9, a-z, _, -, .
|
// Valid characters: 0-9, a-z, _, -, .
|
||||||
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_');
|
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_');
|
||||||
// Only append if sanitized ID contains at least one alphanumeric character
|
if (sanitizedId) {
|
||||||
if (sanitizedId && /[a-z0-9]/i.test(sanitizedId)) {
|
|
||||||
gitHttpUserAgent = `${gitHttpUserAgent} actions_orchestration_id/${sanitizedId}`;
|
gitHttpUserAgent = `${gitHttpUserAgent} actions_orchestration_id/${sanitizedId}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -738,8 +738,7 @@ class GitCommandManager {
|
||||||
// Sanitize the orchestration ID to ensure it contains only valid characters
|
// Sanitize the orchestration ID to ensure it contains only valid characters
|
||||||
// Valid characters: 0-9, a-z, _, -, .
|
// Valid characters: 0-9, a-z, _, -, .
|
||||||
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_')
|
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_')
|
||||||
// Only append if sanitized ID contains at least one alphanumeric character
|
if (sanitizedId) {
|
||||||
if (sanitizedId && /[a-z0-9]/i.test(sanitizedId)) {
|
|
||||||
gitHttpUserAgent = `${gitHttpUserAgent} actions_orchestration_id/${sanitizedId}`
|
gitHttpUserAgent = `${gitHttpUserAgent} actions_orchestration_id/${sanitizedId}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue