make more tests green
This commit is contained in:
parent
f0eb3505fa
commit
0fad659bf7
9 changed files with 36 additions and 33 deletions
|
|
@ -83,6 +83,9 @@
|
||||||
|
|
||||||
- ``nil`` for strings/seqs is finally gone. Instead the default value for
|
- ``nil`` for strings/seqs is finally gone. Instead the default value for
|
||||||
these is ``"" / @[]``.
|
these is ``"" / @[]``.
|
||||||
|
- Accessing the binary zero terminator in Nim's native strings
|
||||||
|
is now invalid. Internally a Nim string still has the trailing zero for
|
||||||
|
zero-copy interoperability with ``cstring``.
|
||||||
|
|
||||||
### Tool changes
|
### Tool changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ template encodeInternal(s: typed, lineLen: int, newLine: string): untyped =
|
||||||
if numLines > 0: inc(total, (numLines - 1) * newLine.len)
|
if numLines > 0: inc(total, (numLines - 1) * newLine.len)
|
||||||
|
|
||||||
result = newString(total)
|
result = newString(total)
|
||||||
var
|
var
|
||||||
i = 0
|
i = 0
|
||||||
r = 0
|
r = 0
|
||||||
currLine = 0
|
currLine = 0
|
||||||
|
|
@ -76,7 +76,7 @@ template encodeInternal(s: typed, lineLen: int, newLine: string): untyped =
|
||||||
currLine = 0
|
currLine = 0
|
||||||
|
|
||||||
if i < s.len-1:
|
if i < s.len-1:
|
||||||
let
|
let
|
||||||
a = ord(s[i])
|
a = ord(s[i])
|
||||||
b = ord(s[i+1])
|
b = ord(s[i+1])
|
||||||
result[r] = cb64[a shr 2]
|
result[r] = cb64[a shr 2]
|
||||||
|
|
@ -130,11 +130,11 @@ proc decode*(s: string): string =
|
||||||
# total is an upper bound, as we will skip arbitrary whitespace:
|
# total is an upper bound, as we will skip arbitrary whitespace:
|
||||||
result = newString(total)
|
result = newString(total)
|
||||||
|
|
||||||
var
|
var
|
||||||
i = 0
|
i = 0
|
||||||
r = 0
|
r = 0
|
||||||
while true:
|
while true:
|
||||||
while s[i] in Whitespace: inc(i)
|
while i < s.len and s[i] in Whitespace: inc(i)
|
||||||
if i < s.len-3:
|
if i < s.len-3:
|
||||||
let
|
let
|
||||||
a = s[i].decodeByte
|
a = s[i].decodeByte
|
||||||
|
|
|
||||||
|
|
@ -25,16 +25,16 @@ proc parseCookies*(s: string): StringTableRef =
|
||||||
result = newStringTable(modeCaseInsensitive)
|
result = newStringTable(modeCaseInsensitive)
|
||||||
var i = 0
|
var i = 0
|
||||||
while true:
|
while true:
|
||||||
while s[i] == ' ' or s[i] == '\t': inc(i)
|
while i < s.len and (s[i] == ' ' or s[i] == '\t'): inc(i)
|
||||||
var keystart = i
|
var keystart = i
|
||||||
while s[i] != '=' and s[i] != '\0': inc(i)
|
while i < s.len and s[i] != '=': inc(i)
|
||||||
var keyend = i-1
|
var keyend = i-1
|
||||||
if s[i] == '\0': break
|
if i >= s.len: break
|
||||||
inc(i) # skip '='
|
inc(i) # skip '='
|
||||||
var valstart = i
|
var valstart = i
|
||||||
while s[i] != ';' and s[i] != '\0': inc(i)
|
while i < s.len and s[i] != ';': inc(i)
|
||||||
result[substr(s, keystart, keyend)] = substr(s, valstart, i-1)
|
result[substr(s, keystart, keyend)] = substr(s, valstart, i-1)
|
||||||
if s[i] == '\0': break
|
if i >= s.len: break
|
||||||
inc(i) # skip ';'
|
inc(i) # skip ';'
|
||||||
|
|
||||||
proc setCookie*(key, value: string, domain = "", path = "",
|
proc setCookie*(key, value: string, domain = "", path = "",
|
||||||
|
|
|
||||||
|
|
@ -190,11 +190,11 @@ proc len*(headers: HttpHeaders): int = return headers.table.len
|
||||||
proc parseList(line: string, list: var seq[string], start: int): int =
|
proc parseList(line: string, list: var seq[string], start: int): int =
|
||||||
var i = 0
|
var i = 0
|
||||||
var current = ""
|
var current = ""
|
||||||
while line[start + i] notin {'\c', '\l', '\0'}:
|
while start+i < line.len and line[start + i] notin {'\c', '\l'}:
|
||||||
i += line.skipWhitespace(start + i)
|
i += line.skipWhitespace(start + i)
|
||||||
i += line.parseUntil(current, {'\c', '\l', ','}, start + i)
|
i += line.parseUntil(current, {'\c', '\l', ','}, start + i)
|
||||||
list.add(current)
|
list.add(current)
|
||||||
if line[start + i] == ',':
|
if start+i < line.len and line[start + i] == ',':
|
||||||
i.inc # Skip ,
|
i.inc # Skip ,
|
||||||
current.setLen(0)
|
current.setLen(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ when false:
|
||||||
var dataAvail = false
|
var dataAvail = false
|
||||||
while dataAvail:
|
while dataAvail:
|
||||||
dataAvail = recvLine(client, buf) # TODO: This is incorrect.
|
dataAvail = recvLine(client, buf) # TODO: This is incorrect.
|
||||||
var L = toLower(buf.string)
|
var L = toLowerAscii(buf.string)
|
||||||
if L.startsWith("content-length:"):
|
if L.startsWith("content-length:"):
|
||||||
var i = len("content-length:")
|
var i = len("content-length:")
|
||||||
while L[i] in Whitespace: inc(i)
|
while L[i] in Whitespace: inc(i)
|
||||||
|
|
@ -199,7 +199,7 @@ when false:
|
||||||
notFound(client)
|
notFound(client)
|
||||||
else:
|
else:
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var ext = splitFile(path).ext.toLower
|
var ext = splitFile(path).ext.toLowerAscii
|
||||||
if ext == ".exe" or ext == ".cgi":
|
if ext == ".exe" or ext == ".cgi":
|
||||||
# XXX: extract interpreter information here?
|
# XXX: extract interpreter information here?
|
||||||
cgi = true
|
cgi = true
|
||||||
|
|
@ -303,7 +303,7 @@ proc next*(s: var Server) =
|
||||||
if s.reqMethod == "POST":
|
if s.reqMethod == "POST":
|
||||||
# Check for Expect header
|
# Check for Expect header
|
||||||
if s.headers.hasKey("Expect"):
|
if s.headers.hasKey("Expect"):
|
||||||
if s.headers["Expect"].toLower == "100-continue":
|
if s.headers["Expect"].toLowerAscii == "100-continue":
|
||||||
s.client.sendStatus("100 Continue")
|
s.client.sendStatus("100 Continue")
|
||||||
else:
|
else:
|
||||||
s.client.sendStatus("417 Expectation Failed")
|
s.client.sendStatus("417 Expectation Failed")
|
||||||
|
|
@ -427,7 +427,7 @@ proc nextAsync(s: PAsyncHTTPServer) =
|
||||||
if s.reqMethod == "POST":
|
if s.reqMethod == "POST":
|
||||||
# Check for Expect header
|
# Check for Expect header
|
||||||
if s.headers.hasKey("Expect"):
|
if s.headers.hasKey("Expect"):
|
||||||
if s.headers["Expect"].toLower == "100-continue":
|
if s.headers["Expect"].toLowerAscii == "100-continue":
|
||||||
s.client.sendStatus("100 Continue")
|
s.client.sendStatus("100 Continue")
|
||||||
else:
|
else:
|
||||||
s.client.sendStatus("417 Expectation Failed")
|
s.client.sendStatus("417 Expectation Failed")
|
||||||
|
|
|
||||||
|
|
@ -29,21 +29,21 @@ proc validEmailAddress*(s: string): bool {.noSideEffect,
|
||||||
chars = Letters + Digits + {'!','#','$','%','&',
|
chars = Letters + Digits + {'!','#','$','%','&',
|
||||||
'\'','*','+','/','=','?','^','_','`','{','}','|','~','-','.'}
|
'\'','*','+','/','=','?','^','_','`','{','}','|','~','-','.'}
|
||||||
var i = 0
|
var i = 0
|
||||||
if s[i] notin chars or s[i] == '.': return false
|
if i >= s.len or s[i] notin chars or s[i] == '.': return false
|
||||||
while s[i] in chars:
|
while i < s.len and s[i] in chars:
|
||||||
if s[i] == '.' and s[i+1] == '.': return false
|
if i+1 < s.len and s[i] == '.' and s[i+1] == '.': return false
|
||||||
inc(i)
|
inc(i)
|
||||||
if s[i] != '@': return false
|
if i >= s.len or s[i] != '@': return false
|
||||||
var j = len(s)-1
|
var j = len(s)-1
|
||||||
if s[j] notin Letters: return false
|
if j >= 0 and s[j] notin Letters: return false
|
||||||
while j >= i and s[j] in Letters: dec(j)
|
while j >= i and s[j] in Letters: dec(j)
|
||||||
inc(i) # skip '@'
|
inc(i) # skip '@'
|
||||||
while s[i] in {'0'..'9', 'a'..'z', '-', '.'}: inc(i)
|
while i < s.len and s[i] in {'0'..'9', 'a'..'z', '-', '.'}: inc(i)
|
||||||
if s[i] != '\0': return false
|
if i != s.len: return false
|
||||||
|
|
||||||
var x = substr(s, j+1)
|
var x = substr(s, j+1)
|
||||||
if len(x) == 2 and x[0] in Letters and x[1] in Letters: return true
|
if len(x) == 2 and x[0] in Letters and x[1] in Letters: return true
|
||||||
case toLower(x)
|
case toLowerAscii(x)
|
||||||
of "com", "org", "net", "gov", "mil", "biz", "info", "mobi", "name",
|
of "com", "org", "net", "gov", "mil", "biz", "info", "mobi", "name",
|
||||||
"aero", "jobs", "museum": return true
|
"aero", "jobs", "museum": return true
|
||||||
else: return false
|
else: return false
|
||||||
|
|
|
||||||
|
|
@ -1126,7 +1126,7 @@ proc unindent*(s: string, count: Natural, padding: string = " "): string
|
||||||
var indentCount = 0
|
var indentCount = 0
|
||||||
for j in 0..<count.int:
|
for j in 0..<count.int:
|
||||||
indentCount.inc
|
indentCount.inc
|
||||||
if line[j .. j + padding.len-1] != padding:
|
if j + padding.len-1 >= line.len or line[j .. j + padding.len-1] != padding:
|
||||||
indentCount = j
|
indentCount = j
|
||||||
break
|
break
|
||||||
result.add(line[indentCount*padding.len .. ^1])
|
result.add(line[indentCount*padding.len .. ^1])
|
||||||
|
|
|
||||||
|
|
@ -232,10 +232,10 @@ proc createAttributeNS*(doc: PDocument, namespaceURI: string, qualifiedName: str
|
||||||
raise newException(EInvalidCharacterErr, "Invalid character")
|
raise newException(EInvalidCharacterErr, "Invalid character")
|
||||||
# Exceptions
|
# Exceptions
|
||||||
if qualifiedName.contains(':'):
|
if qualifiedName.contains(':'):
|
||||||
let qfnamespaces = qualifiedName.toLower().split(':')
|
let qfnamespaces = qualifiedName.toLowerAscii().split(':')
|
||||||
if isNil(namespaceURI):
|
if isNil(namespaceURI):
|
||||||
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
||||||
elif qfnamespaces[0] == "xml" and
|
elif qfnamespaces[0] == "xml" and
|
||||||
namespaceURI != "http://www.w3.org/XML/1998/namespace" and
|
namespaceURI != "http://www.w3.org/XML/1998/namespace" and
|
||||||
qfnamespaces[1] notin stdattrnames:
|
qfnamespaces[1] notin stdattrnames:
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
|
|
@ -311,10 +311,10 @@ proc createElement*(doc: PDocument, tagName: string): PElement =
|
||||||
proc createElementNS*(doc: PDocument, namespaceURI: string, qualifiedName: string): PElement =
|
proc createElementNS*(doc: PDocument, namespaceURI: string, qualifiedName: string): PElement =
|
||||||
## Creates an element of the given qualified name and namespace URI.
|
## Creates an element of the given qualified name and namespace URI.
|
||||||
if qualifiedName.contains(':'):
|
if qualifiedName.contains(':'):
|
||||||
let qfnamespaces = qualifiedName.toLower().split(':')
|
let qfnamespaces = qualifiedName.toLowerAscii().split(':')
|
||||||
if isNil(namespaceURI):
|
if isNil(namespaceURI):
|
||||||
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
||||||
elif qfnamespaces[0] == "xml" and
|
elif qfnamespaces[0] == "xml" and
|
||||||
namespaceURI != "http://www.w3.org/XML/1998/namespace" and
|
namespaceURI != "http://www.w3.org/XML/1998/namespace" and
|
||||||
qfnamespaces[1] notin stdattrnames:
|
qfnamespaces[1] notin stdattrnames:
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
|
|
@ -533,13 +533,13 @@ proc `prefix=`*(n: PNode, value: string) =
|
||||||
|
|
||||||
if isNil(n.fNamespaceURI):
|
if isNil(n.fNamespaceURI):
|
||||||
raise newException(ENamespaceErr, "namespaceURI cannot be nil")
|
raise newException(ENamespaceErr, "namespaceURI cannot be nil")
|
||||||
elif value.toLower() == "xml" and n.fNamespaceURI != "http://www.w3.org/XML/1998/namespace":
|
elif value.toLowerAscii() == "xml" and n.fNamespaceURI != "http://www.w3.org/XML/1998/namespace":
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
"When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"")
|
"When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"")
|
||||||
elif value.toLower() == "xmlns" and n.fNamespaceURI != "http://www.w3.org/2000/xmlns/":
|
elif value.toLowerAscii() == "xmlns" and n.fNamespaceURI != "http://www.w3.org/2000/xmlns/":
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
"When the namespace prefix is \"xmlns\" namespaceURI has to be \"http://www.w3.org/2000/xmlns/\"")
|
"When the namespace prefix is \"xmlns\" namespaceURI has to be \"http://www.w3.org/2000/xmlns/\"")
|
||||||
elif value.toLower() == "xmlns" and n.fNodeType == AttributeNode:
|
elif value.toLowerAscii() == "xmlns" and n.fNodeType == AttributeNode:
|
||||||
raise newException(ENamespaceErr, "An AttributeNode cannot have a prefix of \"xmlns\"")
|
raise newException(ENamespaceErr, "An AttributeNode cannot have a prefix of \"xmlns\"")
|
||||||
|
|
||||||
n.fNodeName = value & ":" & n.fLocalName
|
n.fNodeName = value & ":" & n.fLocalName
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
# bug 2007
|
# bug 2007
|
||||||
|
|
||||||
import asyncdispatch, asyncnet, logging, json, uri, strutils, future
|
import asyncdispatch, asyncnet, logging, json, uri, strutils, sugar
|
||||||
|
|
||||||
type
|
type
|
||||||
Builder = ref object
|
Builder = ref object
|
||||||
|
|
@ -27,7 +27,7 @@ proc newBuild*(onProgress: ProgressCB): Build =
|
||||||
result.onProgress = onProgress
|
result.onProgress = onProgress
|
||||||
|
|
||||||
proc start(build: Build, repo, hash: string) {.async.} =
|
proc start(build: Build, repo, hash: string) {.async.} =
|
||||||
let path = repo.parseUri().path.toLower()
|
let path = repo.parseUri().path.toLowerAscii()
|
||||||
|
|
||||||
proc onProgress(builder: Builder, message: string) {.async.} =
|
proc onProgress(builder: Builder, message: string) {.async.} =
|
||||||
debug($message)
|
debug($message)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue