Code Monkey home page Code Monkey logo

express-request-language's People

Contributors

carlosfaria94 avatar caub avatar ericelliott avatar guidsen avatar holm avatar smoke avatar tinganho avatar yjwong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

express-request-language's Issues

Cookie is set to empty string when language is not specified (also cookie value injection vulnerability)

If you perform a GET request to /languages/ (notice ending slash and that 'language' param is empty), cookie is set as an empty string.

$ curl -s -D - http://localhost:3000/languages/ | grep -i 'Set-Cookie'
Set-Cookie: language=; Path=/

This even applies when you set a language that is not configured in languages option:

var requestLanguage = require('express-request-language');
var cookieParser = require('cookie-parser');
var express = require('express');
var app = express();

app.use(cookieParser());
app.use(requestLanguage({
  languages: ['en', 'es'],
  cookie: {
    name: 'language',
    url: '/languages/{language}'
  }
}));

...and perform such a request:

$ curl -s -D - http://localhost:3000/languages/en | grep -i 'Set-Cookie'
Set-Cookie: language=en; Path=/

$ curl -s -D - http://localhost:3000/languages/notSupportedLanguage | grep -i 'Set-Cookie'
Set-Cookie: language=notSupportedLanguage; Path=/

In my opinion, middleware should validate that the received language is actually supported (in the languages array) before setting the cookie.

Error trying to reach my server without accept-language

If I try to curl http://localhost:3000 my server, I get this error:

TypeError: Cannot read property 'split' of undefined
  at parseAndSortLanguageTags (.../node_modules/accept-language/Build/Source/AcceptLanguage.js:81:40)
  at AcceptLanguage.parse (.../node_modules/accept-language/Build/Source/AcceptLanguage.js:42:43)
  at AcceptLanguage.get (.../node_modules/accept-language/Build/Source/AcceptLanguage.js:36:21)
  at set (.../node_modules/express-request-language/index.js:23:46)
  at .../node_modules/express-request-language/index.js:116:5
  at Layer.handle [as handle_request] (.../node_modules/express/lib/router/layer.js:95:5)
  at trim_prefix (.../node_modules/express/lib/router/index.js:312:13)
  at .../node_modules/express/lib/router/index.js:280:7
  at Function.process_params (.../node_modules/express/lib/router/index.js:330:12)
  at next (.../node_modules/express/lib/router/index.js:271:10)

This error is new and I suspect is introduced by the recent work on the sub-package node-accept-language.

I don't know the best solution, but I personally think that the middleware should fallback to the default locale if no accept-language header is found. Let me know what you think!

Can't import requestLanguage via Typescript

I can't import import * as requestLanguage from 'express-request-language'; when using Typescript 2.5.2. I get this error

[ts] Module '"/node_modules/express-request-language/index"' resolves to a non-module entity and cannot be imported using this construct.

Can't set language

Would like to set language through Set language URL but some languages are not able to set. For example, en-IN.

It won't change the language in the cookie and won't redirect.

Add feature to set a default language

It would be nice if have some way to pass a param like queryName to set a default language.
So, if there isn't a cookie already set and if you pass a prop like: defaultLanguage, then set the default language. I think it could be a very nice feature.

Example:

const languages = ['en', 'pt']

server.use(
    requestLanguage({
      languages: languages,
      queryName: 'lang',
      defaultLanguage: 'en',
      cookie: {
        name: 'DEFAULT_LANGUAGE',
        options: { maxAge: 24 * 3600 * 1000 }
      }
    })
  )

The first time if there is no cookie already set, it would be 'en', ignoring the accept language...

WDYT about it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.