Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 45e0515

Browse files
authored
Merge pull request #4399 from matrix-org/t3chguy/querystring
2 parents b55f69a + 74bd7ca commit 45e0515

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

src/HtmlUtils.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import _linkifyElement from 'linkifyjs/element';
2525
import _linkifyString from 'linkifyjs/string';
2626
import classNames from 'classnames';
2727
import EMOJIBASE_REGEX from 'emojibase-regex';
28-
import url from 'url';
2928
import katex from 'katex';
3029
import { AllHtmlEntities } from 'html-entities';
3130
import { IContent } from 'matrix-js-sdk/src/models/event';
@@ -153,10 +152,8 @@ export function getHtmlText(insaneHtml: string): string {
153152
*/
154153
export function isUrlPermitted(inputUrl: string): boolean {
155154
try {
156-
const parsed = url.parse(inputUrl);
157-
if (!parsed.protocol) return false;
158155
// URL parser protocol includes the trailing colon
159-
return PERMITTED_URL_SCHEMES.includes(parsed.protocol.slice(0, -1));
156+
return PERMITTED_URL_SCHEMES.includes(new URL(inputUrl).protocol.slice(0, -1));
160157
} catch (e) {
161158
return false;
162159
}

src/Lifecycle.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { createClient } from 'matrix-js-sdk/src/matrix';
2121
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
2222
import { MatrixClient } from "matrix-js-sdk/src/client";
2323
import { decryptAES, encryptAES, IEncryptedPayload } from "matrix-js-sdk/src/crypto/aes";
24+
import { QueryDict } from 'matrix-js-sdk/src/utils';
2425

2526
import { IMatrixClientCreds, MatrixClientPeg } from './MatrixClientPeg';
2627
import SecurityCustomisations from "./customisations/Security";
@@ -65,7 +66,7 @@ interface ILoadSessionOpts {
6566
guestIsUrl?: string;
6667
ignoreGuest?: boolean;
6768
defaultDeviceDisplayName?: string;
68-
fragmentQueryParams?: Record<string, string>;
69+
fragmentQueryParams?: QueryDict;
6970
}
7071

7172
/**
@@ -118,8 +119,8 @@ export async function loadSession(opts: ILoadSessionOpts = {}): Promise<boolean>
118119
) {
119120
console.log("Using guest access credentials");
120121
return doSetLoggedIn({
121-
userId: fragmentQueryParams.guest_user_id,
122-
accessToken: fragmentQueryParams.guest_access_token,
122+
userId: fragmentQueryParams.guest_user_id as string,
123+
accessToken: fragmentQueryParams.guest_access_token as string,
123124
homeserverUrl: guestHsUrl,
124125
identityServerUrl: guestIsUrl,
125126
guest: true,
@@ -173,7 +174,7 @@ export async function getStoredSessionOwner(): Promise<[string, boolean]> {
173174
* login, else false
174175
*/
175176
export function attemptTokenLogin(
176-
queryParams: Record<string, string>,
177+
queryParams: QueryDict,
177178
defaultDeviceDisplayName?: string,
178179
fragmentAfterLogin?: string,
179180
): Promise<boolean> {
@@ -198,7 +199,7 @@ export function attemptTokenLogin(
198199
homeserver,
199200
identityServer,
200201
"m.login.token", {
201-
token: queryParams.loginToken,
202+
token: queryParams.loginToken as string,
202203
initial_device_display_name: defaultDeviceDisplayName,
203204
},
204205
).then(function(creds) {

src/components/structures/MatrixChat.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { createClient } from "matrix-js-sdk/src/matrix";
1919
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
2020
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
2121
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
22-
import { sleep, defer, IDeferred } from "matrix-js-sdk/src/utils";
22+
import { sleep, defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils";
2323

2424
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by _AccessibleButton.scss
2525
import 'focus-visible';
@@ -155,7 +155,7 @@ const ONBOARDING_FLOW_STARTERS = [
155155

156156
interface IScreen {
157157
screen: string;
158-
params?: object;
158+
params?: QueryDict;
159159
}
160160

161161
/* eslint-disable camelcase */
@@ -185,17 +185,17 @@ interface IProps { // TODO type things better
185185
onNewScreen: (screen: string, replaceLast: boolean) => void;
186186
enableGuest?: boolean;
187187
// the queryParams extracted from the [real] query-string of the URI
188-
realQueryParams?: Record<string, string>;
188+
realQueryParams?: QueryDict;
189189
// the initial queryParams extracted from the hash-fragment of the URI
190-
startingFragmentQueryParams?: Record<string, string>;
190+
startingFragmentQueryParams?: QueryDict;
191191
// called when we have completed a token login
192192
onTokenLoginCompleted?: () => void;
193193
// Represents the screen to display as a result of parsing the initial window.location
194194
initialScreenAfterLogin?: IScreen;
195195
// displayname, if any, to set on the device when logging in/registering.
196196
defaultDeviceDisplayName?: string;
197197
// A function that makes a registration URL
198-
makeRegistrationUrl: (object) => string;
198+
makeRegistrationUrl: (params: QueryDict) => string;
199199
}
200200

201201
interface IState {
@@ -298,7 +298,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
298298
if (this.screenAfterLogin.screen.startsWith("room/") && params['signurl'] && params['email']) {
299299
// probably a threepid invite - try to store it
300300
const roomId = this.screenAfterLogin.screen.substring("room/".length);
301-
ThreepidInviteStore.instance.storeInvite(roomId, params as IThreepidInviteWireFormat);
301+
ThreepidInviteStore.instance.storeInvite(roomId, params as unknown as IThreepidInviteWireFormat);
302302
}
303303
}
304304

@@ -1952,7 +1952,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
19521952
this.setState({ serverConfig });
19531953
};
19541954

1955-
private makeRegistrationUrl = (params: {[key: string]: string}) => {
1955+
private makeRegistrationUrl = (params: QueryDict) => {
19561956
if (this.props.startingFragmentQueryParams.referrer) {
19571957
params.referrer = this.props.startingFragmentQueryParams.referrer;
19581958
}
@@ -2107,7 +2107,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
21072107
onForgotPasswordClick={showPasswordReset ? this.onForgotPasswordClick : undefined}
21082108
onServerConfigChange={this.onServerConfigChange}
21092109
fragmentAfterLogin={fragmentAfterLogin}
2110-
defaultUsername={this.props.startingFragmentQueryParams.defaultUsername}
2110+
defaultUsername={this.props.startingFragmentQueryParams.defaultUsername as string}
21112111
{...this.getServerProperties()}
21122112
/>
21132113
);

src/utils/HostingLink.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import url from 'url';
18-
import qs from 'qs';
19-
2017
import SdkConfig from '../SdkConfig';
2118
import { MatrixClientPeg } from '../MatrixClientPeg';
2219

@@ -28,11 +25,8 @@ export function getHostingLink(campaign) {
2825
if (MatrixClientPeg.get().getDomain() !== 'matrix.org') return null;
2926

3027
try {
31-
const hostingUrl = url.parse(hostingLink);
32-
const params = qs.parse(hostingUrl.query);
33-
params.utm_campaign = campaign;
34-
hostingUrl.search = undefined;
35-
hostingUrl.query = params;
28+
const hostingUrl = new URL(hostingLink);
29+
hostingUrl.searchParams.set("utm_campaign", campaign);
3630
return hostingUrl.format();
3731
} catch (e) {
3832
return hostingLink;

0 commit comments

Comments
 (0)