Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new txt-1 and txt-2 validation components #181

Merged

Conversation

mmsmits
Copy link
Member

@mmsmits mmsmits commented Aug 14, 2023

fixes #141

@mmsmits mmsmits requested a review from ewoutkramer August 14, 2023 13:05

if (input.Value is null) return (false, null);

var result = XHtml.IsValidNarrativeXhtml(input.Value.ToString(), out var errors);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't trust the input.Value.ToString(), since that's calling the object.ToString function, which might or might not be implemented correctly. Better check that input.Value is actually of type string (as it should be for divs) and just return (false,null) if not (it should only have been generated on elements of the right type). Although I remember another issue where we want to protest if we are run on an invalid value. Double check if other validators do the same when an unexpected datatype arrives in Value.

var results = narrativeSchema!.Validate(justWhiteSpace.ToTypedElement(), _fixture.NewValidationContext());
results.IsSuccessful.Should().Be(false, "Instance failed constraint txt-2 \"The narrative SHALL have some non-whitespace content\"");

results = narrativeSchema!.Validate(invalidHtml.ToTypedElement(), _fixture.NewValidationContext());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be really sure this invariant works, you need to use a forbidden html feature according to the XHTML spec for narrative, e.,g:

The XHTML content SHALL NOT contain a head, a body element, external stylesheet references, deprecated elements, scripts, forms, base/link/xlink, frames, iframes, objects or event related attributes (e.g. onClick).

@mmsmits mmsmits enabled auto-merge August 16, 2023 11:07
@mmsmits mmsmits requested a review from ewoutkramer August 16, 2023 11:07
@mmsmits mmsmits merged commit 5f7c693 into develop Aug 17, 2023
@mmsmits mmsmits deleted the feature/141-improve-error-report-narrative-validation branch August 17, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error reporting for txt-1
2 participants