• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeanderCS / flask-inputfilter / #387

24 May 2025 12:54PM UTC coverage: 93.386% (-0.3%) from 93.644%
#387

Pull #56

coveralls-python

LeanderCS
48 | Updated IsDataclassValidator to also check against their types, including nested dataclasses, lists, and dictionaries
Pull Request #56: 48 | Update ArrayElementValidator and IsDataclassValidator

60 of 69 new or added lines in 4 files covered. (86.96%)

81 existing lines in 14 files now uncovered.

1878 of 2011 relevant lines covered (93.39%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/flask_inputfilter/validators/is_html_validator.py
1
from __future__ import annotations
1✔
2

3
import re
1✔
4
from typing import Any, Optional
1✔
5

6
from flask_inputfilter.exceptions import ValidationError
1✔
7
from flask_inputfilter.validators import BaseValidator
1✔
8

9

10
class IsHtmlValidator(BaseValidator):
1✔
11
    """
12
    Checks if a value contains valid HTML. The validator looks for
13
    the presence of HTML tags in the input string.
14

15
    **Parameters:**
16

17
    - **error_message** (*Optional[str]*): Custom error message if the value
18
        does not contain valid HTML.
19

20
    **Expected Behavior:**
21

22
    Verifies that the input is a string and checks for HTML tags using a
23
    regular expression. Raises a ``ValidationError`` if no HTML tags are found.
24

25
    **Example Usage:**
26

27
    .. code-block:: python
28

29
        class HtmlInputFilter(InputFilter):
30
            def __init__(self):
31
                super().__init__()
32
                self.add('html_content', validators=[
33
                    IsHtmlValidator()
34
                ])
35
    """
36

37
    __slots__ = ("error_message",)
1✔
38

39
    def __init__(self, error_message: Optional[str] = None) -> None:
1✔
40
        self.error_message = (
1✔
41
            error_message or "Value does not contain valid HTML."
42
        )
43

44
    def validate(self, value: Any) -> None:
1✔
45
        if not isinstance(value, str):
1✔
UNCOV
46
            raise ValidationError("Value must be a string.")
×
47

48
        if not re.search(r"<\s*\w+[^>]*", value):
1✔
49
            raise ValidationError(self.error_message)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc