authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-19 22:26:43 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-19 22:26:43 -08:00
log85cc7a78d8a46bd5439aafef2449754877aa8d50
tree75a492202d8e8952b18341ec76c971cb4b05711c
parentbba7e5bd04d3956b80139696424e2c16f32976dd

add step comments and fix args to Validity_Criteria


1 files changed, 17 insertions(+), 5 deletions(-)

idna.zig+17-5
......@@ -140,10 +140,10 @@ fn Processing(
140140 if (label.len == 0) return error.IDNAFailure;
141141 if (extras.matchesAll(u8, label, std.ascii.isAscii)) return error.IDNAFailure;
142142 // 4. Verify that the label meets the validity criteria in Section 4.1, Validity Criteria for Nontransitional Processing. If any of the validity criteria are not satisfied, record that there was an error.
143 try Validity_Criteria(label, CheckHyphens, true, false, UseSTD3ASCIIRules, CheckJoiners, CheckBidi);
143 try Validity_Criteria(label, CheckHyphens, true, UseSTD3ASCIIRules, CheckJoiners, CheckBidi);
144144 } else {
145145 // 1. Verify that the label meets the validity criteria in Section 4.1, Validity Criteria for the input Processing choice (Transitional or Nontransitional). If any of the validity criteria are not satisfied, record that there was an error.
146 try Validity_Criteria(label, CheckHyphens, Transitional_Processing, !Transitional_Processing, UseSTD3ASCIIRules, CheckJoiners, CheckBidi);
146 try Validity_Criteria(label, CheckHyphens, Transitional_Processing, UseSTD3ASCIIRules, CheckJoiners, CheckBidi);
147147 }
148148 }
149149}
......@@ -175,21 +175,33 @@ fn Validity_Criteria(
175175 label: []const u8,
176176 CheckHyphens: bool,
177177 Transitional_Processing: bool, //deprecated,
178 NonTransitional_Processing: bool, //deprecated,
179178 UseSTD3ASCIIRules: bool,
180179 CheckJoiners: bool,
181180 CheckBidi: bool,
182181) !void {
183 // if (!isNFC(label)) return error.IDNAFailure; // TODO:
182 // Each of the following criteria must be satisfied for a non-empty label:
183 if (label.len == 0) return;
184 // 1. The label must be in Unicode Normalization Form NFC.
185 {}
186 // 2. If CheckHyphens, the label must not contain a U+002D HYPHEN-MINUS character in both the third and fourth positions.
184187 if (CheckHyphens and label.len >= 4 and label[2] == '-' and label[3] == '-') return error.IDNAFailure;
188 // 3. If CheckHyphens, the label must neither begin nor end with a U+002D HYPHEN-MINUS character.
185189 if (CheckHyphens and std.mem.startsWith(u8, label, "-")) return error.IDNAFailure;
186190 if (CheckHyphens and std.mem.endsWith(u8, label, "-")) return error.IDNAFailure;
191 // 4. If not CheckHyphens, the label must not begin with “xn--”.
187192 if (!CheckHyphens and std.mem.startsWith(u8, label, "xn--")) return error.IDNAFailure;
193 // 5. The label must not contain a U+002E ( . ) FULL STOP.
188194 if (std.mem.indexOfScalar(u8, label, '.') != null) return error.IDNAFailure;
189195
190196 _ = Transitional_Processing;
191 _ = NonTransitional_Processing;
192197 _ = UseSTD3ASCIIRules;
193198 _ = CheckJoiners;
194199 _ = CheckBidi;
200 // 6. The label must not begin with a combining mark, that is: General_Category=Mark.
201
202 // 7. Each code point in the label must only have certain Status values according to Section 5, IDNA Mapping Table:
203
204 // 8. If CheckJoiners, the label must satisify the ContextJ rules from RFC 5892 Appendix A.
205
206 // 9. If CheckBidi, and if the domain name is a Bidi domain name, then the label must satisfy all six of the numbered conditions in RFC 5893 Section 2.
195207}