Skip to content

Commit

Permalink
fix(form): simplify handling of uriVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 19, 2023
1 parent c33be91 commit d3d2919
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions lib/src/definitions/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,34 +318,23 @@ class Form {
return null;
}

if (affordanceUriVariables.isEmpty) {
throw UriVariableException(
'The Form href $href contains URI '
'variables but the TD does not provide a uriVariables definition.',
if (uriVariables != null) {
// Perform additional validation
_validateUriVariables(
hrefUriVariables,
affordanceUriVariables,
uriVariables,
);
}

if (uriVariables == null) {
throw ValidationException(
'The Form href $href contains URI variables '
'but no values were provided as InteractionOptions.',
);
}

// Perform additional validation
_validateUriVariables(
hrefUriVariables,
affordanceUriVariables,
uriVariables,
);

// As "{" and "}" are "percent encoded" due to Uri.parse(), we need to
// revert the encoding first before we can insert the values.
final decodedHref = Uri.decodeFull(href.toString());

// Everything should be okay at this point, we can simply insert the values
// and return the result.
final newHref = Uri.parse(UriTemplate(decodedHref).expand(uriVariables));
final newHref =
Uri.parse(UriTemplate(decodedHref).expand(uriVariables ?? {}));
return _copy(newHref);
}
}
Expand Down

0 comments on commit d3d2919

Please sign in to comment.