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

Commit 33f2d9f

Browse files
committed
Remove omitLinkHref prop and never populate the href attribute.
1 parent 16a25c4 commit 33f2d9f

File tree

2 files changed

+33
-56
lines changed

2 files changed

+33
-56
lines changed

packages/devtools-reps/src/reps/string.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ StringRep.propTypes = {
3333
object: PropTypes.object.isRequired,
3434
openLink: PropTypes.func,
3535
className: PropTypes.string,
36-
omitLinkHref: PropTypes.bool,
3736
};
3837

3938
function StringRep(props) {
@@ -46,7 +45,6 @@ function StringRep(props) {
4645
escapeWhitespace = true,
4746
member,
4847
openLink,
49-
omitLinkHref = true,
5048
} = props;
5149

5250
let text = object;
@@ -75,7 +73,7 @@ function StringRep(props) {
7573
if (!isLong) {
7674
if (containsURL(text)) {
7775
return span(config,
78-
...getLinkifiedElements(text, shouldCrop && cropLimit, omitLinkHref, openLink));
76+
...getLinkifiedElements(text, shouldCrop && cropLimit, openLink));
7977
}
8078

8179
// Cropping of longString has been handled before formatting.
@@ -166,11 +164,10 @@ function maybeCropString(opts, text) {
166164
*
167165
* @param {String} text: The actual string to linkify.
168166
* @param {Integer | null} cropLimit
169-
* @param {Boolean} omitLinkHref: Do not create an href attribute if true.
170167
* @param {Function} openLink: Function handling the link opening.
171168
* @returns {Array<String|ReactElement>}
172169
*/
173-
function getLinkifiedElements(text, cropLimit, omitLinkHref, openLink) {
170+
function getLinkifiedElements(text, cropLimit, openLink) {
174171
const halfLimit = Math.ceil((cropLimit - ELLIPSIS.length) / 2);
175172
const startCropIndex = cropLimit ? halfLimit : null;
176173
const endCropIndex = cropLimit ? text.length - halfLimit : null;
@@ -198,9 +195,6 @@ function getLinkifiedElements(text, cropLimit, omitLinkHref, openLink) {
198195
items.push(a({
199196
className: "url",
200197
title: token,
201-
href: omitLinkHref === true
202-
? null
203-
: token,
204198
draggable: false,
205199
onClick: openLink
206200
? e => {

packages/devtools-reps/src/reps/tests/string-with-url.js

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const { getGripLengthBubbleText } = require("./test-helpers");
1111
const renderRep = (string, props) => mount(
1212
Rep({
1313
object: string,
14-
omitLinkHref: false,
1514
...props,
1615
})
1716
);
@@ -23,7 +22,7 @@ describe("test String with URL", () => {
2322
const element = renderRep(url, {openLink, useQuotes: false});
2423
expect(element.text()).toEqual(url);
2524
const link = element.find("a");
26-
expect(link.prop("href")).toBe(url);
25+
expect(link.prop("href")).toBe(undefined);
2726
expect(link.prop("title")).toBe(url);
2827

2928
link.simulate("click");
@@ -50,7 +49,7 @@ describe("test String with URL", () => {
5049
const element = renderRep(string, {openLink, useQuotes: false});
5150
expect(element.text()).toEqual(string);
5251
const link = element.find("a");
53-
expect(link.prop("href")).toBe(url);
52+
expect(link.prop("href")).toBe(undefined);
5453
expect(link.prop("title")).toBe(url);
5554

5655
link.simulate("click");
@@ -64,7 +63,7 @@ describe("test String with URL", () => {
6463
const element = renderRep(string, {openLink, useQuotes: false});
6564
expect(element.text()).toEqual(string);
6665
const link = element.find("a");
67-
expect(link.prop("href")).toBe(url);
66+
expect(link.prop("href")).toBe(undefined);
6867
expect(link.prop("title")).toBe(url);
6968

7069
link.simulate("click");
@@ -78,7 +77,7 @@ describe("test String with URL", () => {
7877
const element = renderRep(string, {openLink, useQuotes: true});
7978
expect(element.text()).toEqual(`"\\"${url}\\""`);
8079
const link = element.find("a");
81-
expect(link.prop("href")).toBe(url);
80+
expect(link.prop("href")).toBe(undefined);
8281
expect(link.prop("title")).toBe(url);
8382

8483
link.simulate("click");
@@ -91,7 +90,7 @@ describe("test String with URL", () => {
9190
const element = renderRep(url, {openLink, useQuotes: false});
9291
expect(element.text()).toEqual(url);
9392
const link = element.find("a");
94-
expect(link.prop("href")).toBe(url);
93+
expect(link.prop("href")).toBe(undefined);
9594
expect(link.prop("title")).toBe(url);
9695

9796
link.simulate("click");
@@ -104,7 +103,7 @@ describe("test String with URL", () => {
104103
const element = renderRep(url, {openLink, useQuotes: false});
105104
expect(element.text()).toEqual(url);
106105
const link = element.find("a");
107-
expect(link.prop("href")).toBe(url);
106+
expect(link.prop("href")).toBe(undefined);
108107
expect(link.prop("title")).toBe(url);
109108

110109
link.simulate("click");
@@ -117,7 +116,7 @@ describe("test String with URL", () => {
117116
const element = renderRep(url, {openLink, useQuotes: false});
118117
expect(element.text()).toEqual(url);
119118
const link = element.find("a");
120-
expect(link.prop("href")).toBe(url);
119+
expect(link.prop("href")).toBe(undefined);
121120
expect(link.prop("title")).toBe(url);
122121

123122
link.simulate("click");
@@ -131,7 +130,7 @@ describe("test String with URL", () => {
131130
const element = renderRep(string, {openLink, useQuotes: false});
132131
expect(element.text()).toEqual(string);
133132
const link = element.find("a");
134-
expect(link.prop("href")).toBe(url);
133+
expect(link.prop("href")).toBe(undefined);
135134
expect(link.prop("title")).toBe(url);
136135

137136
link.simulate("click");
@@ -146,7 +145,7 @@ describe("test String with URL", () => {
146145
expect(element.text()).toEqual(string);
147146

148147
const link = element.find("a");
149-
expect(link.prop("href")).toBe(url);
148+
expect(link.prop("href")).toBe(undefined);
150149
expect(link.prop("title")).toBe(url);
151150

152151
link.simulate("click");
@@ -164,13 +163,13 @@ describe("test String with URL", () => {
164163
expect(links.length).toBe(2);
165164

166165
const firstLink = links.at(0);
167-
expect(firstLink.prop("href")).toBe(url1);
166+
expect(firstLink.prop("href")).toBe(undefined);
168167
expect(firstLink.prop("title")).toBe(url1);
169168
firstLink.simulate("click");
170169
expect(openLink).toBeCalledWith(url1);
171170

172171
const secondLink = links.at(1);
173-
expect(secondLink.prop("href")).toBe(url2);
172+
expect(secondLink.prop("href")).toBe(undefined);
174173
expect(secondLink.prop("title")).toBe(url2);
175174
secondLink.simulate("click");
176175
expect(openLink).toBeCalledWith(url2);
@@ -197,7 +196,7 @@ describe("test String with URL", () => {
197196

198197
expect(element.text()).toEqual("http://…ple.com");
199198
const link = element.find("a");
200-
expect(link.prop("href")).toBe(url);
199+
expect(link.prop("href")).toBe(undefined);
201200
expect(link.prop("title")).toBe(url);
202201

203202
link.simulate("click");
@@ -215,7 +214,7 @@ describe("test String with URL", () => {
215214

216215
expect(element.text()).toEqual(url);
217216
const link = element.find("a");
218-
expect(link.prop("href")).toBe(url);
217+
expect(link.prop("href")).toBe(undefined);
219218
expect(link.prop("title")).toBe(url);
220219

221220
link.simulate("click");
@@ -235,7 +234,7 @@ describe("test String with URL", () => {
235234

236235
expect(element.text()).toEqual(url);
237236
const link = element.find("a");
238-
expect(link.prop("href")).toBe(url);
237+
expect(link.prop("href")).toBe(undefined);
239238
expect(link.prop("title")).toBe(url);
240239

241240
link.simulate("click");
@@ -253,11 +252,11 @@ describe("test String with URL", () => {
253252

254253
expect(element.text()).toEqual("- http://example.fr … http://example.us -");
255254
const linkFr = element.find("a").at(0);
256-
expect(linkFr.prop("href")).toBe("http://example.fr");
255+
expect(linkFr.prop("href")).toBe(undefined);
257256
expect(linkFr.prop("title")).toBe("http://example.fr");
258257

259258
const linkUs = element.find("a").at(1);
260-
expect(linkUs.prop("href")).toBe("http://example.us");
259+
expect(linkUs.prop("href")).toBe(undefined);
261260
expect(linkUs.prop("title")).toBe("http://example.us");
262261
});
263262

@@ -272,11 +271,11 @@ describe("test String with URL", () => {
272271

273272
expect(element.text()).toEqual("- http://example.fr -…- http://example.us -");
274273
const linkFr = element.find("a").at(0);
275-
expect(linkFr.prop("href")).toBe("http://example.fr");
274+
expect(linkFr.prop("href")).toBe(undefined);
276275
expect(linkFr.prop("title")).toBe("http://example.fr");
277276

278277
const linkUs = element.find("a").at(1);
279-
expect(linkUs.prop("href")).toBe("http://example.us");
278+
expect(linkUs.prop("href")).toBe(undefined);
280279
expect(linkUs.prop("title")).toBe("http://example.us");
281280
});
282281

@@ -291,11 +290,11 @@ describe("test String with URL", () => {
291290

292291
expect(element.text()).toEqual("- http://e…ample.us -");
293292
const linkFr = element.find("a").at(0);
294-
expect(linkFr.prop("href")).toBe("http://example-long.fr");
293+
expect(linkFr.prop("href")).toBe(undefined);
295294
expect(linkFr.prop("title")).toBe("http://example-long.fr");
296295

297296
const linkUs = element.find("a").at(1);
298-
expect(linkUs.prop("href")).toBe("http://example.us");
297+
expect(linkUs.prop("href")).toBe(undefined);
299298
expect(linkUs.prop("title")).toBe("http://example.us");
300299
});
301300

@@ -310,15 +309,15 @@ describe("test String with URL", () => {
310309

311310
expect(element.text()).toEqual("- http://example-long.fr http:…xample.com http://example.us -");
312311
const linkFr = element.find("a").at(0);
313-
expect(linkFr.prop("href")).toBe("http://example-long.fr");
312+
expect(linkFr.prop("href")).toBe(undefined);
314313
expect(linkFr.prop("title")).toBe("http://example-long.fr");
315314

316315
const linkCom = element.find("a").at(1);
317-
expect(linkCom.prop("href")).toBe("http://example.com");
316+
expect(linkCom.prop("href")).toBe(undefined);
318317
expect(linkCom.prop("title")).toBe("http://example.com");
319318

320319
const linkUs = element.find("a").at(2);
321-
expect(linkUs.prop("href")).toBe("http://example.us");
320+
expect(linkUs.prop("href")).toBe(undefined);
322321
expect(linkUs.prop("title")).toBe("http://example.us");
323322
});
324323

@@ -333,11 +332,11 @@ describe("test String with URL", () => {
333332

334333
expect(element.text()).toEqual("- http://e…ample.us -");
335334
const linkFr = element.find("a").at(0);
336-
expect(linkFr.prop("href")).toBe("http://example.fr");
335+
expect(linkFr.prop("href")).toBe(undefined);
337336
expect(linkFr.prop("title")).toBe("http://example.fr");
338337

339338
const linkUs = element.find("a").at(1);
340-
expect(linkUs.prop("href")).toBe("http://example.us");
339+
expect(linkUs.prop("href")).toBe(undefined);
341340
expect(linkUs.prop("title")).toBe("http://example.us");
342341
});
343342

@@ -352,7 +351,7 @@ describe("test String with URL", () => {
352351

353352
expect(element.text()).toEqual("http://exa…cdefghijkl");
354353
const linkFr = element.find("a").at(0);
355-
expect(linkFr.prop("href")).toBe("http://example.fr");
354+
expect(linkFr.prop("href")).toBe(undefined);
356355
expect(linkFr.prop("title")).toBe("http://example.fr");
357356
});
358357

@@ -367,7 +366,7 @@ describe("test String with URL", () => {
367366

368367
expect(element.text()).toEqual("abcdefghij…xample.fr ");
369368
const linkFr = element.find("a").at(0);
370-
expect(linkFr.prop("href")).toBe("http://example.fr");
369+
expect(linkFr.prop("href")).toBe(undefined);
371370
expect(linkFr.prop("title")).toBe("http://example.fr");
372371
});
373372

@@ -394,7 +393,7 @@ describe("test String with URL", () => {
394393
expect(element.text()).toEqual(`[ "${string}" ]`);
395394

396395
const link = element.find("a");
397-
expect(link.prop("href")).toBe(url);
396+
expect(link.prop("href")).toBe(undefined);
398397
expect(link.prop("title")).toBe(url);
399398

400399
link.simulate("click");
@@ -413,7 +412,7 @@ describe("test String with URL", () => {
413412
expect(element.text()).toEqual(`Array${length} [ "${string}" ]`);
414413

415414
const link = element.find("a");
416-
expect(link.prop("href")).toBe(url);
415+
expect(link.prop("href")).toBe(undefined);
417416
expect(link.prop("title")).toBe(url);
418417

419418
link.simulate("click");
@@ -429,7 +428,7 @@ describe("test String with URL", () => {
429428
expect(element.text()).toEqual(`Object { test: "${string}" }`);
430429

431430
const link = element.find("a");
432-
expect(link.prop("href")).toBe(url);
431+
expect(link.prop("href")).toBe(undefined);
433432
expect(link.prop("title")).toBe(url);
434433

435434
link.simulate("click");
@@ -447,26 +446,10 @@ describe("test String with URL", () => {
447446
expect(element.text()).toEqual(`Object { test: "${string}" }`);
448447

449448
const link = element.find("a");
450-
expect(link.prop("href")).toBe(url);
449+
expect(link.prop("href")).toBe(undefined);
451450
expect(link.prop("title")).toBe(url);
452451

453452
link.simulate("click");
454453
expect(openLink).toBeCalledWith(url);
455454
});
456-
457-
it("does not create an href attribute if omitLinkHref is true", () => {
458-
const url = "http://example.com";
459-
const element = renderRep(url, {omitLinkHref: true, useQuotes: false});
460-
expect(element.text()).toEqual(url);
461-
const link = element.find("a");
462-
expect(link.prop("href")).toBe(null);
463-
});
464-
465-
it("does not create an href attribute if omitLinkHref is undefined", () => {
466-
const url = "http://example.com";
467-
const element = mount(Rep({ object: url, useQuotes: false }));
468-
expect(element.text()).toEqual(url);
469-
const link = element.find("a");
470-
expect(link.prop("href")).toBe(null);
471-
});
472455
});

0 commit comments

Comments
 (0)