(
value: Union[str, Pattern], exact: bool = None
)
| 60 | |
| 61 | |
| 62 | def escape_for_attribute_selector( |
| 63 | value: Union[str, Pattern], exact: bool = None |
| 64 | ) -> str: |
| 65 | if isinstance(value, Pattern): |
| 66 | return escape_regex_for_selector(value) |
| 67 | # TODO: this should actually be |
| 68 | # cssEscape(value).replace(/\\ /g, ' ') |
| 69 | # However, our attribute selectors do not conform to CSS parsing spec, |
| 70 | # so we escape them differently. |
| 71 | return ( |
| 72 | '"' |
| 73 | + value.replace("\\", "\\\\").replace('"', '\\"') |
| 74 | + '"' |
| 75 | + ("s" if exact else "i") |
| 76 | ) |
no test coverage detected