Skip to content

Commit

Permalink
Merge pull request #2680 from iptv-org/patch-2025.02.1
Browse files Browse the repository at this point in the history
Patch 2025.02.1
  • Loading branch information
BellezaEmporium authored Feb 14, 2025
2 parents 0b9276c + b0feab3 commit f5623a4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/commands/channels/lint.mts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ async function main() {
localErrors = localErrors.concat(error.details)
}

xml.split('\n').forEach((line: string, lineIndex: number) => {
const found = line.match(/='/)
if (found) {
const colIndex = found.index || 0
localErrors.push({
line: lineIndex + 1,
col: colIndex + 1,
message: 'Single quotes cannot be used in attributes'
})
}
})

if (localErrors.length) {
console.log(`\n${chalk.underline(filepath)}`)
localErrors.forEach((error: ErrorDetail) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/__data__/input/channels-lint/single_quotes.channels.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding="UTF-8"?>
<channels>
<channel site="singlequotes.com" lang="en" xmltv_id="" site_id="140">Bravo 2</channel>
</channels>
4 changes: 4 additions & 0 deletions tests/__data__/input/channels-lint/valid.channels.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="valid.com" lang="en" xmltv_id="BravoEast.us" site_id="140#Tes't">Bravo's</channel>
</channels>
27 changes: 27 additions & 0 deletions tests/commands/channels/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,31 @@ describe('channels:lint', () => {
expect((error as ExecError).stdout).toContain('2 error(s)')
}
})

it('will show a message if the file contains single quotes', () => {
try {
const cmd =
'npm run channels:lint --- tests/__data__/input/channels-lint/single_quotes.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain('single_quotes.channels.xml')
expect((error as ExecError).stdout).toContain(
'1:14 Single quotes cannot be used in attributes'
)
}
})

it('does not display errors if there are none', () => {
try {
const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/valid.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
} catch (error) {
if (process.env.DEBUG === 'true') console.log((error as ExecError).stdout)
process.exit(1)
}
})
})

0 comments on commit f5623a4

Please sign in to comment.