{"record":{"id":"0b4bf0e2df37e09f","repo":"Molunerfinn/PicGo","slug":"album-url-rewrite-temp-rule-required","errorCode":null,"errorMessage":"ALBUM_URL_REWRITE_TEMP_RULE_REQUIRED","messagePattern":"ALBUM_URL_REWRITE_TEMP_RULE_REQUIRED","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/events/rpc/routes/albumToolbox/builtIn/changeURL.ts","lineNumber":41,"sourceCode":"  return value.map(item => {\n    const raw = (item ?? {}) as Partial<Record<keyof IUrlRewriteRule, unknown>>\n    return {\n      match: String(raw.match ?? ''),\n      replace: String(raw.replace ?? ''),\n      enable: raw.enable === false ? false : true,\n      global: raw.global === true,\n      ignoreCase: raw.ignoreCase === true\n    }\n  }).filter(rule => rule.match.length > 0)\n}\n\nfunction buildFlags (rule: Pick<IUrlRewriteRule, 'global' | 'ignoreCase'>): string {\n  return `${rule.global ? 'g' : ''}${rule.ignoreCase ? 'i' : ''}`\n}\n\nfunction validateRuleOrThrow (rule: IUrlRewriteRule) {\n  if (!rule.match.trim() || !rule.replace.trim()) {\n    throw new Error(T('ALBUM_URL_REWRITE_TEMP_RULE_REQUIRED'))\n  }\n  try {\n    new RegExp(rule.match, buildFlags(rule))\n  } catch (error) {\n    const message = `Invalid URL rewrite regex pattern \"${rule.match}\": ${error instanceof Error ? error.message : String(error)}`\n    logger.error(message)\n    throw new Error(message)\n  }\n}\n\nfunction applyFirstMatchRewrite (ctx: IPicGo, imgItem: ImgInfo, rules: IUrlRewriteRule[]): ImgInfo {\n  const imgInfo = {\n    imgUrl: imgItem.imgUrl,\n    originImgUrl: imgItem.originImgUrl\n  }\n  PicGoUtils.applyUrlRewriteToImgInfo(imgInfo, rules, {\n    log: {\n      error: (...args: Parameters<IPicGo['log']['error']>) => ctx.log.error(...args),","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Molunerfinn/PicGo/blob/07ec7068a5512344da093d49a8408fa63ba3421e/src/main/events/rpc/routes/albumToolbox/builtIn/changeURL.ts#L23-L59","documentation":"validateRuleOrThrow checks a URL rewrite rule before applying it to image URLs. It throws ALBUM_URL_REWRITE_TEMP_RULE_REQUIRED when either the `match` or `replace` part of an IUrlRewriteRule is empty/whitespace-only. The check runs before the regex is even compiled, so it guards against meaningless no-op or destructive empty patterns.","triggerScenarios":"Calling the changeURL RPC route (handle) with a rule whose `match` is '' or '   ', or whose `replace` is empty, e.g. submitting the rewrite form without filling both fields.","commonSituations":"User clicks apply in the album URL-rewrite UI with an untouched form; programmatic rule creation that defaults match/replace to empty strings; clearing the replace field intending a deletion but leaving match empty too.","solutions":["Fill in a non-empty `match` regex and a `replace` string before submitting the rule","Trim the fields client-side and disable the submit button until both are non-empty","If the intent is to remove a matched prefix, use an empty `replace` only with a non-empty `match` — the current validation requires both non-empty, so adjust the rule accordingly"],"exampleFix":"// before\nconst rule = { match: '', replace: '/new/', global: true, ignoreCase: false }\nawait changeURL(rule) // throws ALBUM_URL_REWRITE_TEMP_RULE_REQUIRED\n// after\nconst rule = { match: 'old-host\\\\.com', replace: '/new/', global: true, ignoreCase: false }\nif (rule.match.trim() && rule.replace.trim()) await changeURL(rule)","handlingStrategy":"validation","validationCode":"function isRuleComplete(rule) {\n  return typeof rule.match === 'string' && rule.match.trim() !== '' &&\n         typeof rule.replace === 'string' && rule.replace.trim() !== ''\n}\nif (!isRuleComplete(rule)) throw new Error('match and replace are required')","typeGuard":"function isValidRewriteRule(rule) {\n  return !!rule && typeof rule === 'object' &&\n    typeof rule.match === 'string' && rule.match.trim() !== '' &&\n    typeof rule.replace === 'string' && rule.replace.trim() !== ''\n}","tryCatchPattern":"try {\n  await changeURL(rule)\n} catch (e) {\n  if (e.message.includes('ALBUM_URL_REWRITE_TEMP_RULE_REQUIRED')) {\n    showFormError('Match and replace fields are required')\n  } else throw e\n}","preventionTips":["Validate match/replace non-empty in the form before submitting","Trim user input before constructing the rule object","Disable the apply button until both fields have content"],"tags":["validation","url-rewrite","regex","input-required"],"backgroundTag":"empty-required-field-validation","analyzedSha":"07ec7068a5512344da093d49a8408fa63ba3421e","analyzedAt":"2026-08-30T01:45:22.289Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}