|
| 1 | +## Can ErbParser handle all valid Ruby code? |
| 2 | + |
| 3 | +No it cannot. Ruby has a very complex syntax. In a library like this, it would be a fool's |
| 4 | +errand to try to handle every weird syntactic construct that could technically be |
| 5 | +considered valid Ruby. Instead, this library is designed to handle only the constructs |
| 6 | +that would commonly appear inside ERB tags. In other words, the basics of the language. |
| 7 | + |
| 8 | +Just avoid exotic syntactic constructs, and you should be fine. (You shouldn't do anything |
| 9 | +syntactically fancy in an ERB template anyway--it's bad coding style.) In particular, you |
| 10 | +must avoid Ruby's weirder string literals, such as the following: |
| 11 | + |
| 12 | + %q!This is a valid string literal, but you must not use this syntax.! |
| 13 | + |
| 14 | +Also be wary of tricky escape sequences. If you absolutely must use unusual syntax, and it |
| 15 | +breaks ErbParser, consider moving the offending code into a class or module external to |
| 16 | +the ERB template. |
| 17 | + |
| 18 | +Nonetheless, the library *does* account for and allow the following string literal |
| 19 | +formats: |
| 20 | + |
| 21 | + "string" |
| 22 | + 'string' |
| 23 | + %q(string (string) string) |
| 24 | + %Q(string (string) string) |
| 25 | + %(string (string) string) |
| 26 | + %q{string {string} string} |
| 27 | + %Q{string {string} string} |
| 28 | + %{string {string} string} |
| 29 | + |
| 30 | +This parser is *not* hardened against malicious input. But then, you shouldn't be |
| 31 | +accepting ERB as untrusted input anyway, because ERB allows arbitrary code execution. |
| 32 | + |
| 33 | +## What does ErbParser do with invalid ERB or Ruby code? |
| 34 | + |
| 35 | +If you pass code containing a syntax error, the parsing behavior is undefined. You may get |
| 36 | +an exception, or you may just get nonsensical results. It depends on the type of the |
| 37 | +syntax error. |
0 commit comments