From 1f485fde8302c1583709372d4e8306bbad03ba62 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 13 Jan 2017 14:38:13 +0800 Subject: [PATCH] fix: make sure signed=false on set/get cookie (#24) --- .travis.yml | 9 ++++++--- LICENSE | 2 +- appveyor.yml | 16 ++++++++++++++++ index.js | 19 ++++--------------- package.json | 25 +++++++++++++++---------- test/index.test.js | 13 ------------- 6 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml index 98f4890..5ec1467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/LICENSE b/LICENSE index 70c3765..e968a27 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..2efd0fa --- /dev/null +++ b/appveyor.yml @@ -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 diff --git a/index.js b/index.js index 892c0b6..f4877e7 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,5 @@ -/** - * Copyright(c) koajs and other contributors. - * MIT Licensed - * - * Authors: - * fengmk2 (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; diff --git a/package.json b/package.json index 4d291f5..3e7e71c 100644 --- a/package.json +++ b/package.json @@ -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 (http://fengmk2.com)", + "ci": { + "version": "4, 6, 7" + }, + "author": "fengmk2 (https://fengmk2.com)", "license": "MIT" } diff --git a/test/index.test.js b/test/index.test.js index 310e668..640984d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,17 +1,5 @@ -/** - * Copyright(c) koajs and other contributors. - * MIT Licensed - * - * Authors: - * fengmk2 (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; } -