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

Remove language from urlFor #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/_common/__tests__/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ describe('Url', () => {
function runTests(url) {
setURL(url);
const website_url = Url.websiteUrl();
const language = 'en';
const query_string = 'market=forex&duration_amount=5&no_value=';
const params_obj = { market: 'forex', duration_amount: '5', no_value: '' };
const url_no_qs = `${website_url}${language}/trading.html`;
const url_no_qs = `${website_url}trading.html`;
const url_with_qs = `${url_no_qs}?${query_string}`;
const home_url = `${website_url}${language}/home.html`;
const home_url = `${website_url}home.html`;

describe('.paramsHash()', () => {
it('returns correct object', () => {
Expand Down Expand Up @@ -49,14 +48,14 @@ function runTests(url) {
expect(Url.urlFor('trading', query_string)).to.eq(url_with_qs);
});
it('returns the correct language', () => {
expect(Url.urlFor('home', undefined, 'es')).to.eq(`${website_url}es/home.html`);
expect(Url.urlFor('home', undefined, 'es')).to.eq(`${website_url}home.html`);
});
it('ignores invalid characters', () => {
expect(Url.urlFor('`~!@#$%^&*)(=+\[}{\]\\\"\';:\?><,|')).to.eq(home_url);
});
it('handles all valid characters', () => {
expect(Url.urlFor('metatrader/comparison-4_vs_5'))
.to.eq(`${website_url}${language}/metatrader/comparison-4_vs_5.html`);
.to.eq(`${website_url}metatrader/comparison-4_vs_5.html`);
});
});

Expand Down
11 changes: 4 additions & 7 deletions src/_common/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const urlForLanguage = require('./language').urlFor;
const urlLang = require('./language').urlLang;
const getLanguage = require('./language').get;
const getCurrentProductionDomain = require('../config').getCurrentProductionDomain;
require('url-polyfill');

Expand Down Expand Up @@ -37,14 +37,11 @@ const Url = (() => {
const normalizePath = path => (path ? path.replace(/(^\/|\/$|[^a-zA-Z0-9-_/])/g, '') : '');

const urlFor = (path, pars, language, should_change_to_legacy = false) => {
const lang = (language || urlLang()).toLowerCase();
// url language might differ from passed language, so we will always replace using the url language
const url_lang = (language ? urlLang().toLowerCase() : lang);
const url = window.location.href;
let domain = url.substring(0, url.indexOf(`/${url_lang}/`) + url_lang.length + 2);
const lang = (language || getLanguage()).toLowerCase();
let domain = 'https://' + window.location.hostname + '/';
if (should_change_to_legacy) {
if (/localhost|binary\.sx/.test(domain)) {
domain = `https://binary.com/${url_lang}/`;
domain = `https://binary.com/${lang || 'en'}/`;
} else {
domain = domain.replace(/deriv\.app/, 'binary.com');
}
Expand Down