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

Add value sanitization support #11

Closed
jaap3 opened this issue Nov 1, 2018 · 0 comments
Closed

Add value sanitization support #11

jaap3 opened this issue Nov 1, 2018 · 0 comments

Comments

@jaap3
Copy link
Owner

jaap3 commented Nov 1, 2018

The fields provided by this project should have some (optional) way of sanitizing their values. For example by running bleach on the field content.

e.g.:

RichTextWidget(..., sanitizer=bleach.clean) or RichTextField(..., sanitizer=bleach.clean)

This could be implemented using a custom to_python (similar to the strip option of Django's Charfield) or clean implementation (similar to the coerce option of Django's TypeChoiceField`.

Sanitation should not be enabled by default (i.e. the default could be an identify function lambda value: value). Enabling it should be strongly recommended in the documentation however.

Sanitation should also be configurable through Django settings, ideally on a per profile basis (with a fallback to a global sanitizer).

e.g.:

DJRICHTEXTFIELD_CONFIG = {
    'settings': ...,
    'profiles': {
        'basic': ....,
        'fancy': ....
    },
    'sanitizer': 'bleach.clean',  # 'dotted.path' string
    'sanitizer_profiles': {
        'basic': partial(bleach.clean, tags=['a', 'b', 'em', 'i', 'strong']),
    }
}

(dotted paths should be resolved using Django's import_string function).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant