fix: make sure signed=false on set/get cookie (#24)

master
fengmk2 2017-01-13 14:38:13 +08:00 committed by GitHub
parent 1327118e10
commit 1f485fde83
6 changed files with 42 additions and 42 deletions

View File

@ -1,9 +1,12 @@
sudo: false
language: node_js
node_js:
- '5'
- '4'
- '6'
- '7'
install:
- npm i npminstall && npminstall
script:
- 'npm run test-cov'
- npm run ci
after_script:
- 'npm i codecov.io && cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js'
- npminstall codecov && codecov

View File

@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal

16
appveyor.yml Normal file
View File

@ -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

View File

@ -1,17 +1,5 @@
/**
* Copyright(c) koajs and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
*/
'use strict';
/**
* Module dependencies.
*/
const debug = require('debug')('koa-locales');
const ini = require('ini');
const util = require('util');
@ -27,11 +15,11 @@ const DEFAULT_OPTIONS = {
localeAlias: {},
cookieMaxAge: '1y',
dir: undefined,
dirs: [path.join(process.cwd(), 'locales')],
dirs: [ path.join(process.cwd(), 'locales') ],
functionName: '__',
};
module.exports = function (app, options) {
module.exports = (app, options) => {
options = assign({}, DEFAULT_OPTIONS, options);
const defaultLocale = formatLocale(options.defaultLocale);
const queryField = options.queryField;
@ -139,7 +127,7 @@ module.exports = function (app, options) {
return this.__locale;
}
const cookieLocale = this.cookies.get(cookieField);
const cookieLocale = this.cookies.get(cookieField, { signed: false });
let locale = this.query[queryField] || cookieLocale;
if (!locale) {
// 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
httpOnly: false,
maxAge: cookieMaxAge,
signed: false,
});
}
this.__locale = locale;

View File

@ -7,14 +7,15 @@
"index.js"
],
"scripts": {
"test": "eslint . && mocha --check-leaks -R spec -t 5000 test/*.test.js",
"test-cov": "istanbul cover _mocha -- --check-leaks -t 5000 test/*.test.js",
"test": "eslint . && mocha -R spec -t 5000 test/*.test.js",
"cov": "istanbul cover _mocha -- -t 5000 test/*.test.js",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod -w --prefix '^'",
"contributors": "contributors -f plain -o AUTHORS"
},
"dependencies": {
"debug": "^2.2.0",
"debug": "^2.6.0",
"humanize-ms": "^1.2.0",
"ini": "^1.3.4",
"object-assign": "^4.1.0"
@ -22,15 +23,16 @@
"devDependencies": {
"autod": "2",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.0",
"benchmark": "^2.1.3",
"contributors": "*",
"egg-ci": "^1.1.0",
"eslint": "1",
"istanbul": "*",
"koa": "^1.2.0",
"mm": "^1.3.5",
"koa": "^1.2.4",
"mm": "^2.0.0",
"mocha": "*",
"pedding": "^1.0.0",
"supertest": "^1.2.0"
"pedding": "^1.1.0",
"supertest": "^2.0.1"
},
"homepage": "https://github.com/koajs/locales",
"repository": {
@ -50,8 +52,11 @@
"koa"
],
"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"
}

View File

@ -1,17 +1,5 @@
/**
* Copyright(c) koajs and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
*/
'use strict';
/**
* Module dependencies.
*/
const assert = require('assert');
const koa = require('koa');
const request = require('supertest');
@ -482,4 +470,3 @@ function createApp(options) {
return app;
}