mirror of
https://github.com/actions/checkout.git
synced 2026-01-21 16:18:54 +08:00
Simplify orchestration ID validation to accept any non-empty sanitized value
Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>
This commit is contained in:
parent
4b8779770e
commit
818b5b3072
3 changed files with 5 additions and 7 deletions
|
|
@ -493,7 +493,7 @@ describe('git user-agent with orchestration ID', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not append orchestration ID when it becomes empty after sanitization', async () => {
|
it('should sanitize orchestration ID to underscores when it contains only invalid characters', async () => {
|
||||||
const orchId = '()///'
|
const orchId = '()///'
|
||||||
process.env['ACTIONS_ORCHESTRATION_ID'] = orchId
|
process.env['ACTIONS_ORCHESTRATION_ID'] = orchId
|
||||||
|
|
||||||
|
|
@ -520,11 +520,11 @@ describe('git user-agent with orchestration ID', () => {
|
||||||
// Call a git command to trigger env capture after user-agent is set
|
// Call a git command to trigger env capture after user-agent is set
|
||||||
await git.init()
|
await git.init()
|
||||||
|
|
||||||
// Verify the user agent does NOT contain orchestration ID when sanitized ID is empty
|
// Verify the user agent contains orchestration ID with sanitized underscores
|
||||||
expect(git).toBeDefined()
|
expect(git).toBeDefined()
|
||||||
expect(capturedEnv).toBeDefined()
|
expect(capturedEnv).toBeDefined()
|
||||||
expect(capturedEnv['GIT_HTTP_USER_AGENT']).toBe(
|
expect(capturedEnv['GIT_HTTP_USER_AGENT']).toBe(
|
||||||
'git/2.18 (github-actions-checkout)'
|
'git/2.18 (github-actions-checkout) actions_orchestration_id/_____'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
3
dist/index.js
vendored
3
dist/index.js
vendored
|
|
@ -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…
Add table
Add a link
Reference in a new issue