fix: make sure signed=false on set/get cookie (#24)
parent
1327118e10
commit
1f485fde83
|
@ -1,9 +1,12 @@
|
||||||
sudo: false
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '5'
|
|
||||||
- '4'
|
- '4'
|
||||||
|
- '6'
|
||||||
|
- '7'
|
||||||
|
install:
|
||||||
|
- npm i npminstall && npminstall
|
||||||
script:
|
script:
|
||||||
- 'npm run test-cov'
|
- npm run ci
|
||||||
after_script:
|
after_script:
|
||||||
- 'npm i codecov.io && cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js'
|
- npminstall codecov && codecov
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
This software is licensed under the MIT License.
|
This software is licensed under the MIT License.
|
||||||
|
|
||||||
Copyright (c) 2015 koajs and other contributors
|
Copyright (c) 2015 - 2017 koajs and other contributors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- nodejs_version: '4'
|
||||||
|
- nodejs_version: '6'
|
||||||
|
- nodejs_version: '7'
|
||||||
|
|
||||||
|
install:
|
||||||
|
- ps: Install-Product node $env:nodejs_version
|
||||||
|
- npm i npminstall && node_modules\.bin\npminstall
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- node --version
|
||||||
|
- npm --version
|
||||||
|
- npm run ci
|
||||||
|
|
||||||
|
build: off
|
19
index.js
19
index.js
|
@ -1,17 +1,5 @@
|
||||||
/**
|
|
||||||
* Copyright(c) koajs and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const debug = require('debug')('koa-locales');
|
const debug = require('debug')('koa-locales');
|
||||||
const ini = require('ini');
|
const ini = require('ini');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
@ -27,11 +15,11 @@ const DEFAULT_OPTIONS = {
|
||||||
localeAlias: {},
|
localeAlias: {},
|
||||||
cookieMaxAge: '1y',
|
cookieMaxAge: '1y',
|
||||||
dir: undefined,
|
dir: undefined,
|
||||||
dirs: [path.join(process.cwd(), 'locales')],
|
dirs: [ path.join(process.cwd(), 'locales') ],
|
||||||
functionName: '__',
|
functionName: '__',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function (app, options) {
|
module.exports = (app, options) => {
|
||||||
options = assign({}, DEFAULT_OPTIONS, options);
|
options = assign({}, DEFAULT_OPTIONS, options);
|
||||||
const defaultLocale = formatLocale(options.defaultLocale);
|
const defaultLocale = formatLocale(options.defaultLocale);
|
||||||
const queryField = options.queryField;
|
const queryField = options.queryField;
|
||||||
|
@ -139,7 +127,7 @@ module.exports = function (app, options) {
|
||||||
return this.__locale;
|
return this.__locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cookieLocale = this.cookies.get(cookieField);
|
const cookieLocale = this.cookies.get(cookieField, { signed: false });
|
||||||
let locale = this.query[queryField] || cookieLocale;
|
let locale = this.query[queryField] || cookieLocale;
|
||||||
if (!locale) {
|
if (!locale) {
|
||||||
// Accept-Language: zh-CN,zh;q=0.5
|
// Accept-Language: zh-CN,zh;q=0.5
|
||||||
|
@ -191,6 +179,7 @@ module.exports = function (app, options) {
|
||||||
// make sure brower javascript can read the cookie
|
// make sure brower javascript can read the cookie
|
||||||
httpOnly: false,
|
httpOnly: false,
|
||||||
maxAge: cookieMaxAge,
|
maxAge: cookieMaxAge,
|
||||||
|
signed: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.__locale = locale;
|
this.__locale = locale;
|
||||||
|
|
25
package.json
25
package.json
|
@ -7,14 +7,15 @@
|
||||||
"index.js"
|
"index.js"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "eslint . && mocha --check-leaks -R spec -t 5000 test/*.test.js",
|
"test": "eslint . && mocha -R spec -t 5000 test/*.test.js",
|
||||||
"test-cov": "istanbul cover _mocha -- --check-leaks -t 5000 test/*.test.js",
|
"cov": "istanbul cover _mocha -- -t 5000 test/*.test.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
"ci": "npm run lint && npm run cov",
|
||||||
"autod": "autod -w --prefix '^'",
|
"autod": "autod -w --prefix '^'",
|
||||||
"contributors": "contributors -f plain -o AUTHORS"
|
"contributors": "contributors -f plain -o AUTHORS"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "^2.2.0",
|
"debug": "^2.6.0",
|
||||||
"humanize-ms": "^1.2.0",
|
"humanize-ms": "^1.2.0",
|
||||||
"ini": "^1.3.4",
|
"ini": "^1.3.4",
|
||||||
"object-assign": "^4.1.0"
|
"object-assign": "^4.1.0"
|
||||||
|
@ -22,15 +23,16 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autod": "2",
|
"autod": "2",
|
||||||
"beautify-benchmark": "^0.2.4",
|
"beautify-benchmark": "^0.2.4",
|
||||||
"benchmark": "^2.1.0",
|
"benchmark": "^2.1.3",
|
||||||
"contributors": "*",
|
"contributors": "*",
|
||||||
|
"egg-ci": "^1.1.0",
|
||||||
"eslint": "1",
|
"eslint": "1",
|
||||||
"istanbul": "*",
|
"istanbul": "*",
|
||||||
"koa": "^1.2.0",
|
"koa": "^1.2.4",
|
||||||
"mm": "^1.3.5",
|
"mm": "^2.0.0",
|
||||||
"mocha": "*",
|
"mocha": "*",
|
||||||
"pedding": "^1.0.0",
|
"pedding": "^1.1.0",
|
||||||
"supertest": "^1.2.0"
|
"supertest": "^2.0.1"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/koajs/locales",
|
"homepage": "https://github.com/koajs/locales",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -50,8 +52,11 @@
|
||||||
"koa"
|
"koa"
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.12.0"
|
"node": ">=4.0.0"
|
||||||
},
|
},
|
||||||
"author": "fengmk2 <m@fengmk2.com> (http://fengmk2.com)",
|
"ci": {
|
||||||
|
"version": "4, 6, 7"
|
||||||
|
},
|
||||||
|
"author": "fengmk2 <m@fengmk2.com> (https://fengmk2.com)",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,5 @@
|
||||||
/**
|
|
||||||
* Copyright(c) koajs and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const koa = require('koa');
|
const koa = require('koa');
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
@ -482,4 +470,3 @@ function createApp(options) {
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue