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

Commit b3f65fb

Browse files
committed
Fix string with URL when passed member.open
Fixes #864. I created a new bundle and made sure the JSON viewer now behaves as it should.
1 parent d500975 commit b3f65fb

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ function StringRep(props) {
8787
*/
8888
function getLinkifiedElements(text, cropLimit, omitLinkHref, openLink) {
8989
const halfLimit = Math.ceil((cropLimit - ELLIPSIS.length) / 2);
90-
const startCropIndex = halfLimit;
91-
const endCropIndex = text.length - halfLimit;
90+
const startCropIndex = cropLimit ? halfLimit : null;
91+
const endCropIndex = cropLimit ? text.length - halfLimit : null;
9292

9393
// As we walk through the tokens of the source string, we make sure to preserve
9494
// the original whitespace that separated the tokens.
@@ -151,13 +151,17 @@ function getLinkifiedElements(text, cropLimit, omitLinkHref, openLink) {
151151
* @param {String} text: The substring to crop.
152152
* @param {Integer} offset: The offset corresponding to the index at which the substring
153153
* is in the parent string.
154-
* @param {Integer} startCropIndex: the index where the start of the crop should happen
155-
* in the parent string
156-
* @param {Integer} endCropIndex: the index where the end of the crop should happen
157-
* in the parent string
154+
* @param {Integer|null} startCropIndex: the index where the start of the crop should
155+
* happen in the parent string.
156+
* @param {Integer|null} endCropIndex: the index where the end of the crop should happen
157+
* in the parent string
158158
* @returns {String|null} The cropped substring, or null if the text is completly cropped.
159159
*/
160160
function getCroppedString(text, offset = 0, startCropIndex, endCropIndex) {
161+
if (!startCropIndex) {
162+
return text;
163+
}
164+
161165
const start = offset;
162166
const end = offset + text.length;
163167

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,26 @@ describe("test String with URL", () => {
202202
expect(openLink).toBeCalledWith(url);
203203
});
204204

205+
it("renders URL on an open string", () => {
206+
const url = "http://example.com";
207+
const openLink = jest.fn();
208+
const element = renderRep(url, {
209+
openLink,
210+
useQuotes: false,
211+
member: {
212+
open: true
213+
}
214+
});
215+
216+
expect(element.text()).toEqual(url);
217+
const link = element.find("a");
218+
expect(link.prop("href")).toBe(url);
219+
expect(link.prop("title")).toBe(url);
220+
221+
link.simulate("click");
222+
expect(openLink).toBeCalledWith(url);
223+
});
224+
205225
it("renders URLs with a stripped string between", () => {
206226
const text = "- http://example.fr --- http://example.us -";
207227
const openLink = jest.fn();

0 commit comments

Comments
 (0)