Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor lngPathCorrector #174

Merged
merged 1 commit into from
Feb 22, 2019

Conversation

capellini
Copy link
Contributor

Refactor lngPathCorrector to have the following signature:

lngPathCorrector(
  { defaultLanguage: string, allLanguages: string[] },
  { href: object | string, as?: string },
  language: string
): { as: string, href: object }

Note that, to provide the greatest flexibility, I assumed that the href object need not contain a query key, if passed in by the user. I also do some type checking to ensure that href is either a string or an object and as, if defined, is a string.

Also, in my testing, I noticed that, should a parsed URL object that contain both a search and query key, the search key string overrides any changes made to the query object.

> const { format, parse } = require('url')
undefined

> const foo = parse('/foo?option1=value1#hash1', true)
undefined

> foo.query.lng = 'de'
'de'

> foo
Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: '#hash1',
  search: '?option1=value1',
  query: { option1: 'value1', lng: 'de' },
  pathname: '/foo',
  path: '/foo?option1=value1',
  href: '/foo?option1=value1#hash1' }

> format(foo)
'/foo?option1=value1#hash1'

> delete foo.search
true

> format(foo)
'/foo?option1=value1&lng=de#hash1'

Considering in past PRs we had such trouble with manipulating a string query, I opted to remove the search key from the href object, should it exist (for example, if a user passes in a URL object as the href object) and, if necessary, add a query object to href, should it not exist (for example, if a user passes in an object without the query object in it). I thought that this was a better option than attempting to add lng to both the query object and the search string.

Resolves #155.

@capellini capellini force-pushed the lng-path-corrector-refactor branch 3 times, most recently from 6d3354e to be4a791 Compare February 12, 2019 15:10
@isaachinman
Copy link
Contributor

@capellini Sorry, just getting back to this. Can you resolve the conflict?

@capellini
Copy link
Contributor Author

@isaachinman No worries. Rebased.

@isaachinman
Copy link
Contributor

@capellini This looks good, not sure I have any technical feedback, actually. Did you do any manual regression testing?

@capellini
Copy link
Contributor Author

Did you do any manual regression testing?

Yes, I did, but if you'd prefer, we can wait on this until #186 is merged, which should give us some added confidence that it works.

@isaachinman
Copy link
Contributor

I merged #186. Can you rebase here and force push to rerun the CI? Then we can merge this.

Refactor lngPathCorrector to have the following signature:

lngPathCorrector(
  { defaultLanguage: string, allLanguages: string[] },
  { href: object | string, as?: string },
  language: string
): { as: string, href: object }
@capellini
Copy link
Contributor Author

Rebased.

@isaachinman isaachinman merged commit 8bf6fb4 into i18next:master Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants