Skip to content

Commit

Permalink
input sanitation
Browse files Browse the repository at this point in the history
  • Loading branch information
FG-TUM committed Jan 25, 2024
1 parent 49bd4d6 commit 75edcd0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import {
getUrlToFile
} from './utils'

/**
* Checks if file extensions start with a '.' and then only consist of letters and numbers.
* @param extensions Array of extensions to check.
* @return True if extension matches the sane pattern.
*/
function extensionsIsSane(extension: string): boolean {
// The regex checks if e starts with '.' and only has letters or numbers afterwards until the end.
return /^\.[a-zA-Z0-9]+$/.test(extension)
}

/**
* Get the list of file tags anywhere in the given file.
* A file tag is defined as a continuous word without `/` or white spaces and terminated by a file ending.
Expand Down Expand Up @@ -328,8 +338,7 @@ export async function run(): Promise<void> {
const ghToken = core.getInput('githubToken')
// Sanity check
if (ghToken === undefined) {
core.setFailed(`ghToken === undefined. Aborting`)
return
throw new Error(`ghToken === undefined. Aborting`)
}
// Split on any whitespace, ',', ';', or combination
const splitRegex = /[\s,;]+/
Expand All @@ -343,13 +352,23 @@ export async function run(): Promise<void> {
const docFileExtensions = (core.getInput('docFileExtensions') || 'md')
.split(splitRegex)
.map(s => (s.startsWith('.') ? s : `.${s}`))
if (!docFileExtensions.every(e => extensionsIsSane(e))) {
throw new Error(
`At least one doc extension contains something other than numbers or letters.\ndocFileExtensions: ${docFileExtensions}`
)
}
core.info(`Doc file extensions: ${docFileExtensions}`)
// Parse source extensions, split, and make sure they start with '.'
const srcFileExtensions = (
core.getInput('srcFileExtensions') || 'cpp h txt'
)
.split(splitRegex)
.map(s => (s.startsWith('.') ? s : `.${s}`))
if (!srcFileExtensions.every(e => extensionsIsSane(e))) {
throw new Error(
`At least one src extension contains something other than numbers or letters.\nsrcFileExtensions: ${srcFileExtensions}`
)
}
core.info(`Source file extensions: ${srcFileExtensions}`)
const docFiles = getDocFiles(dirs, docFileExtensions, recurseUserDocDirs)
core.info(`User doc files: ${docFiles}`)
Expand Down

0 comments on commit 75edcd0

Please sign in to comment.