Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/0.0.3'

  • Loading branch information...
commit 6f7caefff01fc8d9388c8ee0837400b66e5312f1 2 parents 5e09d3b + 6cf5441
@chick307 authored
View
2  Gruntfile.coffee
@@ -8,7 +8,7 @@ module.exports = (grunt) ->
mocha:
all:
- src: ['test/index.html']
+ src: ['test/index.html', 'test/issue-3.html']
options:
run: true
View
9 README.md
@@ -43,7 +43,10 @@ require(['base64codec'], function(base64codec) {
### web browsers
-```javascript
-window.base64codec.encode('\0\0\0'); // -> 'AAAA'
-window.base64codec.decode('AAAA'); // -> '\0\0\0'
+```html
+<script src="base64codec.js"></script>
+<script>
+ window.base64codec.encode('\0\0\0'); // -> 'AAAA'
+ window.base64codec.decode('AAAA'); // -> '\0\0\0'
+</script>
```
View
4 base64codec.js
@@ -156,7 +156,7 @@ void function(global, callback) {
'5': 57, '6': 58, '7': 59, '8': 60, '9': 61, '+': 62, '/': 63
};
return function atob(base64String) {
- base64String = base64String.replace(/[\n\r]+|=+$/g, '');
+ base64String = base64String.replace(/=+$/g, '');
if (/[^A-Z0-9\+\/]/i.test(base64String) ||
base64String.length % 4 === 1) {
throw new Error('Invalid character error.');
@@ -176,7 +176,7 @@ void function(global, callback) {
ATOB_TABLE[base64String.charAt(i++)] << 12;
result += String.fromCharCode(block >>> 16 & 0xFF);
if (i < l) {
- block |= base64String.charAt(i) << 6;
+ block |= ATOB_TABLE[base64String.charAt(i)] << 6;
result += String.fromCharCode(block >>> 8 & 0xFF);
}
}
View
59 package.json
@@ -1,31 +1,32 @@
{
- "author": "chick307 <chick307@gmail.com>",
- "name": "base64codec",
- "description": "Base64 encoding/decoding library for JavaScript.",
- "version": "0.0.2",
- "main": "base64codec.js",
- "scripts": {
- "test": "grunt test"
- },
- "homepage": "https://github.com/chick307/base64codec",
- "bugs": "https://github.com/chick307/base64codec/issues",
- "repository": {
- "type": "git",
- "url": "git://github.com/chick307/base64codec.git"
- },
- "dependencies": {},
- "devDependencies": {
- "mocha": "1.8.x",
- "grunt": "0.4.x",
- "grunt-mocha": "0.2.x",
- "grunt-simple-mocha": "0.3.x",
- "grunt-contrib-watch": "0.3.x"
- },
- "optionalDependencies": {},
- "engines": {
- "node": "*"
- },
- "jam": {
- "dependencies": {}
- }
+ "author": "chick307 <chick307@gmail.com>",
+ "name": "base64codec",
+ "description": "Base64 encoding/decoding library for JavaScript.",
+ "version": "0.0.3",
+ "license": "MIT",
+ "keywords": ["base64"],
+ "main": "base64codec.js",
+ "readmeFilename": "README.md",
+ "homepage": "https://github.com/chick307/base64codec",
+ "bugs": "https://github.com/chick307/base64codec/issues",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/chick307/base64codec.git"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "directories": {
+ "test": "test"
+ },
+ "devDependencies": {
+ "mocha": "1.8.x",
+ "grunt": "0.4.x",
+ "grunt-mocha": "0.2.x",
+ "grunt-simple-mocha": "0.3.x",
+ "grunt-contrib-watch": "0.3.x"
+ },
+ "jam": {
+ "dependencies": {}
+ }
}
View
10 test/base64codec-test.js
@@ -161,4 +161,14 @@ describe('base64codec', function() {
});
});
});
+
+ describe('issue#3', function() {
+ var base64String = 'cyJ9XX0=';
+ var expected = 's"}]}';
+
+ it('decode(' + JSON.stringify(base64String) + ')', function() {
+ var actual = base64codec.decode(base64String);
+ assert.strictEqual(actual, expected);
+ });
+ });
});
View
18 test/issue-3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>base64codec test</title>
+ <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
+ <script>window.atob = void 0</script>
+</head>
+<body>
+ <div id="mocha"></div>
+ <script src="../node_modules/mocha/mocha.js"></script>
+ <script>mocha.setup('bdd');</script>
+ <script src="assert.js"></script>
+ <script src="../base64codec.js"></script>
+ <script src="./base64codec-test.js"></script>
+ <script>mocha.run();</script>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.