diff options
| -rw-r--r-- | src/buffer/buffer.nim | 16 | ||||
| -rw-r--r-- | src/utils/twtstr.nim | 23 |
2 files changed, 23 insertions, 16 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index 59655bed..cba31dbb 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -790,22 +790,6 @@ proc constructEntryList(form: HTMLFormElement, submitter: Element = nil, encodin return entrylist #https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm -proc makeCRLF(s: string): string = - result = newStringOfCap(s.len) - var i = 0 - while i < s.len - 1: - if s[i] == '\r' and s[i + 1] != '\n': - result &= '\r' - result &= '\n' - elif s[i] != '\r' and s[i + 1] == '\n': - result &= s[i] - result &= '\r' - result &= '\n' - inc i - else: - result &= s[i] - inc i - proc serializeMultipartFormData(kvs: seq[(string, string)]): MimeData = for it in kvs: let name = makeCRLF(it[0]) diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 1afe54d9..9a70539a 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -902,3 +902,26 @@ func padToWidth*(str: string, size: int, schar = '$'): string = result &= r w += r.width result &= schar + +#https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm +proc makeCRLF*(s: string): string = + result = newStringOfCap(s.len) + var i = 0 + while i < s.len - 1: + if s[i] == '\r' and s[i + 1] != '\n': + result &= '\r' + result &= '\n' + elif s[i] != '\r' and s[i + 1] == '\n': + result &= s[i] + result &= '\r' + result &= '\n' + inc i + else: + result &= s[i] + inc i + if i < s.len: + if s[i] == '\r': + result &= '\r' + result &= '\n' + else: + result &= s[i] |