Fix block channel channel ID validation (#4366)

This commit is contained in:
absidue 2023-11-21 03:22:29 +01:00 committed by GitHub
parent 3fc2e547c9
commit c219926c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue'
import FtInputTags from '../../components/ft-input-tags/ft-input-tags.vue'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import { showToast } from '../../helpers/utils'
import { checkYoutubeId, findChannelTagInfo } from '../../helpers/channels'
import { checkYoutubeChannelId, findChannelTagInfo } from '../../helpers/channels'
export default defineComponent({
name: 'PlayerSettings',
@ -152,7 +152,7 @@ export default defineComponent({
showToast(this.$t('Settings.Distraction Free Settings.Hide Channels Already Exists'))
},
validateChannelId: function (text) {
return checkYoutubeId(text)
return checkYoutubeChannelId(text)
},
findChannelTagInfo: async function (text) {
return await findChannelTagInfo(text, this.backendOptions)
@ -167,7 +167,7 @@ export default defineComponent({
if (tag.invalid) continue
// process if no preferred name and is possibly a YouTube ID
if (tag.preferredName === '' && checkYoutubeId(tag.name)) {
if (tag.preferredName === '' && checkYoutubeChannelId(tag.name)) {
this.channelHiderDisabled = true
const { preferredName, icon, iconHref, invalidId } = await this.findChannelTagInfo(tag.name)

View File

@ -43,7 +43,7 @@ async function findChannelById(id, backendOptions) {
* @returns {Promise<{icon: string, iconHref: string, preferredName: string} | { invalidId: boolean }>}
*/
export async function findChannelTagInfo(id, backendOptions) {
if (!/UC\S{22}/.test(id)) return { invalidId: true }
if (!checkYoutubeChannelId(id)) return { invalidId: true }
try {
const channel = await findChannelById(id, backendOptions)
if (!process.env.IS_ELECTRON || backendOptions.preference === 'invidious') {
@ -71,6 +71,6 @@ export async function findChannelTagInfo(id, backendOptions) {
* @param {string} id
* @returns {boolean}
*/
export function checkYoutubeId(id) {
return /UC\S{22}/.test(id)
export function checkYoutubeChannelId(id) {
return /^UC[\w-]{22}$/.test(id)
}