Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tested with Node 0.3.7 in preparation for Node 0.4.0's arrival.

Removed dependency on base64 library.

Using MD5 to check validity of uploaded file.

Fixed few tests failing due to Express 1.0.1 on Node 0.3.x.
  • Loading branch information...
commit bf31ec78fa8124f60337e4dd55ad18a4ab4c74a1 1 parent 2d291fe
@assaf assaf authored
View
12 CHANGELOG.md
@@ -4,20 +4,16 @@ zombie.js-changelog(7) -- Changelog
### Version 0.8.12 Pending
+Tested with Node 0.3.7 in preparation for Node 0.4.0 (Assaf Arkin).
+
Fix firing the `change` event on `SELECT` elements when using jQuery
(Damian Janowski).
-You can now run Zombie without base64 module, if you're not planning on
-uploading binary files. If you are uploading binary files, you'll need
-to `npm install base64` (Assaf Arkin).
-
-Tested with Node 0.3.7 (Assaf Arkin).
-
Fix for `jQuery.ajax` receiving a non-string `data` option (Damian
Janowski).
- 283 Tests
- 4.6 sec to complete
+ 284 Tests
+ 4.9 sec to complete
### Version 0.8.11 2011-01-25
View
5 package.json
@@ -30,7 +30,7 @@
"test": "vows"
},
"engines": {
- "node": ">= 0.2 < 0.3"
+ "node": ">= 0.2.5"
},
"dependencies": {
"html5": "0.2.12",
@@ -38,8 +38,7 @@
"mime": "1.2.1"
},
"devDependencies": {
- "base64": ">1.0.1",
- "coffee-script": ">= 1.0.0",
+ "coffee-script": ">= 1.0.1",
"docco": "0.3.0",
"express": "1.0.3",
"ronn": "0.3.5",
View
25 spec/forms-spec.coffee
@@ -1,5 +1,7 @@
require("./helpers")
{ vows: vows, assert: assert, zombie: zombie, brains: brains } = require("vows")
+fs = require("fs")
+crypto = require("crypto")
brains.get "/forms/form", (req, res)-> res.send """
@@ -79,7 +81,18 @@ brains.get "/forms/form", (req, res)-> res.send """
</body>
</html>
"""
-brains.post "/forms/submit", (req, res)-> res.send """
+brains.post "/forms/submit", (req, res)->
+ # These fixes necessary with Express 1.0.3 under Node 0.3.x. Otherwise,
+ # bodyDecoder takes care of these mapping.
+ req.body.hungry ||= req.body["hungry[]"]
+ req.body.hobbies ||= req.body["hobbies[]"]
+ if req.body["addresses[][street]"]
+ req.body.addresses = []
+ for i,j of req.body["addresses[][street]"]
+ req.body.addresses.push street: j
+ req.body.addresses.push city: req.body["addresses[][city]"][i]
+
+ res.send """
<html>
<body>
<div id="name">#{req.body.name}</div>
@@ -119,10 +132,11 @@ brains.get "/forms/upload", (req, res)-> res.send """
"""
brains.post "/forms/upload", (req, res)->
[text, image] = [req.body.text, req.body.image]
+ digest = crypto.createHash("md5").update(image).digest("hex") if image
res.send """
<html>
<head><title>#{text?.filename || image?.filename}</title></head>
- <body>#{text || image?.length}</body>
+ <body>#{text || digest}</body>
</html>
"""
@@ -405,9 +419,12 @@ vows.describe("Forms").addBatch(
"file upload (binary)":
zombie.wants "http://localhost:3003/forms/upload"
topic: (browser)->
- filename = __dirname + "/data/zombie.jpg"
- browser.attach("image", filename).pressButton "Upload", @callback
+ @filename = __dirname + "/data/zombie.jpg"
+ browser.attach("image", @filename).pressButton "Upload", @callback
"should upload include name": (browser)-> assert.equal browser.text("title"), "zombie.jpg"
+ "should upload file": (browser)->
+ digest = crypto.createHash("md5").update(fs.readFileSync(@filename)).digest("hex")
+ assert.equal browser.text("body").trim(), digest
"file upload (empty)":
zombie.wants "http://localhost:3003/forms/upload"
View
6 spec/helpers.coffee
@@ -108,9 +108,7 @@ express.bodyDecoder.decode["multipart/form-data"] = (body)->
headers
, {}
- # Base64 encoding is optional.
- if headers["content-transfer-encoding"] == "base64"
- contents = require("base64").decode(contents)
+ contents = new Buffer(contents, "base64") if headers["content-transfer-encoding"] == "base64"
contents.mime = headers["content-type"].split(/;/)[0]
# We're looking for the content-disposition header, which has
@@ -124,7 +122,7 @@ express.bodyDecoder.decode["multipart/form-data"] = (body)->
# From content disposition we can tell the field name, if it's a
# file upload, also the file name. Content type is separate
# header.
- contents = new String(contents)
+ contents = new String(contents) if typeof contents is "string"
contents.filename = pairs.filename if pairs.filename
parts[pairs.name] = contents if pairs.name
parts
View
19 src/zombie/resources.coffee
@@ -171,23 +171,18 @@ class Resources extends Array
content = value
mime = "text/plain"
+ switch encoding
+ when "base64" then content = content.toString("base64")
+ when "7bit" then content = content.toString("ascii")
+ when null
+ else throw new Error("Unsupported transfer encoding #{encoding}")
+
lines.push disp
lines.push "Content-Type: #{mime}"
lines.push "Content-Length: #{content.length}"
lines.push "Content-Transfer-Encoding: #{encoding}" if encoding
lines.push ""
- switch encoding
- when "base64"
- # Base64 encoding is optional, loaded on demand.
- try
- base64 = require("base64")
- catch ex
- throw new Error("Base64 encoding support is optional, you need to `npm install base64`")
- lines.push base64.encode(content).replace(/(.{76})/g, "$1\r\n")
- when null
- lines.push content
- else
- throw new Error("Unsupported transfer encoding #{encoding}")
+ lines.push content
lines.push "--#{boundary}"
)
if lines.length < 2
Please sign in to comment.
Something went wrong with that request. Please try again.