(command string)
| 50 | } |
| 51 | |
| 52 | func ExtractQuotedContent(command string) QuotedExtraction { |
| 53 | var withDQ, fully, keep strings.Builder |
| 54 | for i := 0; i < len(command); { |
| 55 | ch := command[i] |
| 56 | switch { |
| 57 | case ch == '\'': |
| 58 | i++ |
| 59 | for i < len(command) && command[i] != '\'' { |
| 60 | i++ |
| 61 | } |
| 62 | if i < len(command) { |
| 63 | i++ |
| 64 | } |
| 65 | case ch == '"': |
| 66 | keep.WriteByte(ch) |
| 67 | withDQ.WriteByte(ch) |
| 68 | i++ |
| 69 | for i < len(command) && command[i] != '"' { |
| 70 | if command[i] == '\\' && i+1 < len(command) { |
| 71 | keep.WriteByte(command[i]) |
| 72 | withDQ.WriteByte(command[i]) |
| 73 | i++ |
| 74 | keep.WriteByte(command[i]) |
| 75 | withDQ.WriteByte(command[i]) |
| 76 | } else { |
| 77 | keep.WriteByte(command[i]) |
| 78 | withDQ.WriteByte(command[i]) |
| 79 | } |
| 80 | i++ |
| 81 | } |
| 82 | if i < len(command) { |
| 83 | keep.WriteByte(command[i]) |
| 84 | withDQ.WriteByte(command[i]) |
| 85 | i++ |
| 86 | } |
| 87 | case ch == '\\' && i+1 < len(command): |
| 88 | keep.WriteByte(ch) |
| 89 | keep.WriteByte(command[i+1]) |
| 90 | withDQ.WriteByte(ch) |
| 91 | withDQ.WriteByte(command[i+1]) |
| 92 | fully.WriteByte(command[i+1]) |
| 93 | i += 2 |
| 94 | default: |
| 95 | keep.WriteByte(ch) |
| 96 | withDQ.WriteByte(ch) |
| 97 | fully.WriteByte(ch) |
| 98 | i++ |
| 99 | } |
| 100 | } |
| 101 | return QuotedExtraction{ |
| 102 | WithDoubleQuotes: withDQ.String(), |
| 103 | FullyUnquoted: fully.String(), |
| 104 | UnquotedKeepQuoteChars: keep.String(), |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | type regexFinding struct { |
| 109 | re *regexp.Regexp |
no test coverage detected