{"record":{"id":"8ef4997b8119bd34","repo":"phacility/phabricator","slug":"rrule-count-value-s-is-invalid-count-must-be-a","errorCode":null,"errorMessage":"RRULE COUNT value \"%s\" is invalid: count must be at least 1.","messagePattern":"RRULE COUNT value \"(.+?)\" is invalid: count must be at least 1\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/calendar/parser/data/PhutilCalendarRecurrenceRule.php","lineNumber":353,"sourceCode":"          $weekday,\n          implode(', ', $constants)));\n    }\n\n    return $map[$weekday];\n  }\n\n  public function setStartDateTime(PhutilCalendarDateTime $start) {\n    $this->startDateTime = $start;\n    return $this;\n  }\n\n  public function getStartDateTime() {\n    return $this->startDateTime;\n  }\n\n  public function setCount($count) {\n    if ($count < 1) {\n      throw new Exception(\n        pht(\n          'RRULE COUNT value \"%s\" is invalid: count must be at least 1.',\n          $count));\n    }\n\n    $this->count = $count;\n    return $this;\n  }\n\n  public function getCount() {\n    return $this->count;\n  }\n\n  public function setUntil(PhutilCalendarDateTime $until) {\n    $this->until = $until;\n    return $this;\n  }\n","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/calendar/parser/data/PhutilCalendarRecurrenceRule.php#L335-L371","documentation":"PhutilCalendarRecurrenceRule::setCount() rejects counts below 1. RFC 5545 defines COUNT as a positive occurrence count; COUNT=0 would mean a rule with no occurrences and is invalid. Note that the string '0' passes the earlier digit-regex normalization, casts to int 0, and then fails here.","triggerScenarios":"An ICS RRULE containing COUNT=0; newFromDictionary(array('FREQ' => 'DAILY', 'COUNT' => 0)); programmatic rules built from user input allowing zero.","commonSituations":"Broken calendar exports; edge-case values from other vendors; forms that default a repeat count field to 0.","solutions":["Remove the COUNT part entirely (rule then runs to UNTIL or forever) or set it to at least 1.","Validate external input: if ((int)$count < 1) drop the COUNT component rather than passing it through.","Only clamp with max(1, $count) if a single occurrence is an acceptable business default; otherwise reject the RRULE."],"exampleFix":"// before\n$rule->setCount(0);\n// after\n// omit setCount() entirely, or:\n$rule->setCount(1);","handlingStrategy":"validation","validationCode":"$count = idx($dict, 'COUNT');\nif ($count !== null) {\n  $count = (int)$count;\n  if ($count < 1) {\n    unset($dict['COUNT']); // no meaningful COUNT; let the rule run to UNTIL/forever\n  } else {\n    $dict['COUNT'] = $count;\n  }\n}","typeGuard":"function isValidRruleCount($count) {\n  return is_int($count) && $count >= 1;\n}","tryCatchPattern":null,"preventionTips":["Treat COUNT < 1 in external ICS as invalid and drop the COUNT component on import.","Validate repeat-count form fields with min=1.","Do not clamp silently unless one occurrence is an acceptable default."],"tags":["phutil","calendar","rrule","count","out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}