{"record":{"id":"7f6755f0beb1c129","repo":"ruby/ruby","slug":"invalid-zone-identifier-for-address","errorCode":null,"errorMessage":"invalid zone identifier for address","messagePattern":"invalid zone identifier for address","errorType":"exception","errorClass":"InvalidAddressError","httpStatus":null,"severity":"error","filePath":"lib/ipaddr.rb","lineNumber":583,"sourceCode":"  # Returns the IPv6 zone identifier, if present.\n  # Raises InvalidAddressError if not an IPv6 address.\n  def zone_id\n    if @family == Socket::AF_INET6\n      @zone_id\n    else\n      raise InvalidAddressError, \"not an IPv6 address\"\n    end\n  end\n\n  # Returns the IPv6 zone identifier, if present.\n  # Raises InvalidAddressError if not an IPv6 address.\n  def zone_id=(zid)\n    if @family == Socket::AF_INET6\n      case zid\n      when nil, /\\A%(\\w+)\\z/\n        @zone_id = zid\n      else\n        raise InvalidAddressError, \"invalid zone identifier for address\"\n      end\n    else\n      raise InvalidAddressError, \"not an IPv6 address\"\n    end\n  end\n\n  protected\n  # :stopdoc:\n\n  def begin_addr\n    @addr & @mask_addr\n  end\n\n  def end_addr\n    case @family\n    when Socket::AF_INET\n      @addr | (IN4MASK ^ @mask_addr)\n    when Socket::AF_INET6","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/lib/ipaddr.rb#L565-L601","documentation":"IPAddr#zone_id= assigns the zone identifier of an IPv6 address. The value must be nil (clears the zone) or a String matching the strict pattern of a percent sign followed by word characters only. Anything else - 'eth0' without %, '%eth 0' with a space, an Integer scope id - raises InvalidAddressError 'invalid zone identifier for address'.","triggerScenarios":"ip.zone_id = 'eth0' (missing leading %); ip.zone_id = '%fe80::1' (colons are not word characters); ip.zone_id = 2 (Integer from if_nametoindex); strings with hyphens, dots, or spaces in the zone name.","commonSituations":"Passing interface names from Socket.getifaddrs or config straight through without the % sigil; APIs that return numeric scope ids; zone names containing '-' or '.' (e.g. 'eth0.100') which \\w does not match.","solutions":["Prefix % when missing: zid = zid.start_with?('%') ? zid : \"%#{zid}\"","Pass nil to clear the zone identifier","Pre-validate against the accepted pattern before assigning"],"exampleFix":"# before\nip.zone_id = if_name # 'eth0' -> InvalidAddressError\n\n# after\nip.zone_id = \"%#{if_name}\"","handlingStrategy":"validation","validationCode":"zid = nil if zid.nil?\nzid = \"%#{zid}\" if zid.is_a?(String) && !zid.start_with?('%')\nraise ArgumentError, 'bad zone id' unless zid.nil? || zid.match?(/\\A%\\w+\\z/)\nip.zone_id = zid","typeGuard":"def valid_zone_id?(v)\n  v.nil? || (v.is_a?(String) && v.match?(/\\A%\\w+\\z/))\nend","tryCatchPattern":"begin\n  ip.zone_id = zid\nrescue IPAddr::InvalidAddressError => e\n  errors << e.message\nend","preventionTips":["Always store zone ids with the leading % ('%eth0', not 'eth0')","Pass nil to clear instead of an empty string","Remember \\w excludes '.', '-', and ':' - pre-validate names like 'eth0.100'"],"tags":["ruby","ipaddr","ipv6","zone-id","input-validation"],"backgroundTag":"invalid-zone-identifier","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}