Skip to content

Commit d3d2919

Browse files
committed
fix(form): simplify handling of uriVariables
1 parent c33be91 commit d3d2919

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

lib/src/definitions/form.dart

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -318,34 +318,23 @@ class Form {
318318
return null;
319319
}
320320

321-
if (affordanceUriVariables.isEmpty) {
322-
throw UriVariableException(
323-
'The Form href $href contains URI '
324-
'variables but the TD does not provide a uriVariables definition.',
321+
if (uriVariables != null) {
322+
// Perform additional validation
323+
_validateUriVariables(
324+
hrefUriVariables,
325+
affordanceUriVariables,
326+
uriVariables,
325327
);
326328
}
327329

328-
if (uriVariables == null) {
329-
throw ValidationException(
330-
'The Form href $href contains URI variables '
331-
'but no values were provided as InteractionOptions.',
332-
);
333-
}
334-
335-
// Perform additional validation
336-
_validateUriVariables(
337-
hrefUriVariables,
338-
affordanceUriVariables,
339-
uriVariables,
340-
);
341-
342330
// As "{" and "}" are "percent encoded" due to Uri.parse(), we need to
343331
// revert the encoding first before we can insert the values.
344332
final decodedHref = Uri.decodeFull(href.toString());
345333

346334
// Everything should be okay at this point, we can simply insert the values
347335
// and return the result.
348-
final newHref = Uri.parse(UriTemplate(decodedHref).expand(uriVariables));
336+
final newHref =
337+
Uri.parse(UriTemplate(decodedHref).expand(uriVariables ?? {}));
349338
return _copy(newHref);
350339
}
351340
}

0 commit comments

Comments
 (0)