Skip to content

Commit

Permalink
🐛 Fix invalid branch names
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed May 7, 2024
1 parent 469f04d commit ba18ada
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/qodana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export function getQodanaSha256MismatchMessage(
* @param branchName the branch name to sanitize.
*/
export function validateBranchName(branchName: string): string {
const validBranchNameRegex = /^[a-zA-Z0-9/\-_]+$/
const validBranchNameRegex = /^[a-zA-Z0-9/\-_.]+$/
if (!validBranchNameRegex.test(branchName)) {
throw new Error(
`Invalid branch name: not allowed characters are used: ${branchName}`
Expand Down
17 changes: 16 additions & 1 deletion scan/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
getQodanaScanArgs,
Inputs,
QODANA_OPEN_IN_IDE_NAME,
QODANA_REPORT_URL_NAME
QODANA_REPORT_URL_NAME,
validateBranchName
} from '../../common/qodana'
import {
Annotation,
Expand All @@ -18,6 +19,20 @@ import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'

test('validate branch names', () => {
let validBranchNames = [
'main',
'dependabot/go_modules/cmd/dependencies.1987366a71',
'refs/heads/main',
'refs/tags/v1.0.0',
'refs/pull/123/merge',
'v2024.1.3'
]
for (let branchName of validBranchNames) {
expect(validateBranchName(branchName)).toEqual(branchName)
}
})

test('qodana scan command args', () => {
const inputs = inputsDefaultFixture()
const result = getQodanaScanArgs(
Expand Down
2 changes: 1 addition & 1 deletion scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24439,7 +24439,7 @@ function getQodanaSha256MismatchMessage(expected, actual) {
return `Downloaded Qodana CLI binary is corrupted. Expected SHA-256 checksum: ${expected}, actual checksum: ${actual}`;
}
function validateBranchName(branchName) {
const validBranchNameRegex = /^[a-zA-Z0-9/\-_]+$/;
const validBranchNameRegex = /^[a-zA-Z0-9/\-_.]+$/;
if (!validBranchNameRegex.test(branchName)) {
throw new Error(
`Invalid branch name: not allowed characters are used: ${branchName}`
Expand Down
2 changes: 1 addition & 1 deletion vsts/QodanaScan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function getQodanaSha256MismatchMessage(expected, actual) {
return `Downloaded Qodana CLI binary is corrupted. Expected SHA-256 checksum: ${expected}, actual checksum: ${actual}`;
}
function validateBranchName(branchName) {
const validBranchNameRegex = /^[a-zA-Z0-9/\-_]+$/;
const validBranchNameRegex = /^[a-zA-Z0-9/\-_.]+$/;
if (!validBranchNameRegex.test(branchName)) {
throw new Error(
`Invalid branch name: not allowed characters are used: ${branchName}`
Expand Down

0 comments on commit ba18ada

Please sign in to comment.