Add fromhex filter (#39096)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Petro31 2025-05-26 04:21:47 -07:00 committed by GitHub
parent eb44138fd1
commit 40b74dff0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1174,6 +1174,7 @@ Some examples:
- Filter `urlencode` will convert an object to a percent-encoded ASCII text string (e.g., for HTTP requests using `application/x-www-form-urlencoded`). - Filter `urlencode` will convert an object to a percent-encoded ASCII text string (e.g., for HTTP requests using `application/x-www-form-urlencoded`).
- Filter `slugify(separator="_")` will convert a given string into a "slug". - Filter `slugify(separator="_")` will convert a given string into a "slug".
- Filter `ordinal` will convert an integer into a number defining a position in a series (e.g., `1st`, `2nd`, `3rd`, `4th`, etc). - Filter `ordinal` will convert an integer into a number defining a position in a series (e.g., `1st`, `2nd`, `3rd`, `4th`, etc).
- Filter `value | from_hex` Decodes a hex string to raw bytes.
- Filter `value | base64_decode` Decodes a base 64 string to a string, by default utf-8 encoding is used. - Filter `value | base64_decode` Decodes a base 64 string to a string, by default utf-8 encoding is used.
- Filter `value | base64_decode("ascii")` Decodes a base 64 string to a string, using ascii encoding. - Filter `value | base64_decode("ascii")` Decodes a base 64 string to a string, using ascii encoding.
- Filter `value | base64_decode(None)` Decodes a base 64 string to raw bytes. - Filter `value | base64_decode(None)` Decodes a base 64 string to raw bytes.
@ -1185,6 +1186,8 @@ Some examples:
- `{{ "aG9tZWFzc2lzdGFudA==" | base64_decode }}` - renders as `homeassistant` - `{{ "aG9tZWFzc2lzdGFudA==" | base64_decode }}` - renders as `homeassistant`
- `{{ "aG9tZWFzc2lzdGFudA==" | base64_decode(None) }}` - renders as `b'homeassistant'` - `{{ "aG9tZWFzc2lzdGFudA==" | base64_decode(None) }}` - renders as `b'homeassistant'`
- `{{ "0F010003" | from_hex }}` - renders as `b'\x0f\x01\x00\x03'`
- `{{ "0F010003" | from_hex | base64_encode }}` - renders as `DwEAAw==`
{% endraw %} {% endraw %}