aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2017-03-14 10:09:15 +0100
committerStas Vilchik <vilchiks@gmail.com>2017-03-14 10:09:15 +0100
commite0489108823967b6d6ac2a49be3a8a449b13116a (patch)
treef8f9fae4121ca5cb92531f5430927677ac8bc382 /server
parent7c8e31c4a69e96199305c6bf1e43fa2cd5a552be (diff)
downloadsonarqube-e0489108823967b6d6ac2a49be3a8a449b13116a.tar.gz
sonarqube-e0489108823967b6d6ac2a49be3a8a449b13116a.zip
fix js exception when location message is empty
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js2
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineCode-test.js27
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCode-test.js.snap10
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/helpers/indexing.js2
4 files changed, 39 insertions, 2 deletions
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js b/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js
index 944922c0fe8..840623fed9f 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js
+++ b/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js
@@ -150,7 +150,7 @@ export default class LineCode extends React.PureComponent {
onClick={e =>
this.handleLocationMessageClick(e, location.flowIndex, location.locationIndex)}>
{location.index && <strong>{location.index}: </strong>}
- {limitString(location.msg)}
+ {location.msg ? limitString(location.msg) : ''}
</a>
);
};
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineCode-test.js b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineCode-test.js
index eedeb69252e..c174394c33e 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineCode-test.js
+++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineCode-test.js
@@ -48,3 +48,30 @@ it('render code', () => {
);
expect(wrapper).toMatchSnapshot();
});
+
+it('should handle empty location message', () => {
+ const line = {
+ line: 3,
+ code: '<span class="k">class</span>'
+ };
+ const issueLocations = [{ from: 0, to: 5, line: 3 }];
+ const secondaryIssueLocations = [{ from: 6, to: 9, line: 3 }];
+ const secondaryIssueLocationMessages = [{ flowIndex: 0, locationIndex: 0 }];
+ const selectedIssueLocation = { from: 6, to: 9, line: 3, flowIndex: 0, locationIndex: 0 };
+ const wrapper = shallow(
+ <LineCode
+ highlightedSymbol="sym1"
+ issueKeys={['issue-1', 'issue-2']}
+ issueLocations={issueLocations}
+ line={line}
+ onIssueSelect={jest.fn()}
+ onSelectLocation={jest.fn()}
+ onSymbolClick={jest.fn()}
+ secondaryIssueLocations={secondaryIssueLocations}
+ secondaryIssueLocationMessages={secondaryIssueLocationMessages}
+ selectedIssue="issue-1"
+ selectedIssueLocation={selectedIssueLocation}
+ showIssues={true}/>
+ );
+ expect(wrapper.find('.source-line-issue-locations')).toMatchSnapshot();
+});
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCode-test.js.snap b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCode-test.js.snap
index ecf619bfa06..3e4499bb1bf 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCode-test.js.snap
+++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCode-test.js.snap
@@ -32,3 +32,13 @@ exports[`test render code 1`] = `
selectedIssue="issue-1" />
</td>
`;
+
+exports[`test should handle empty location message 1`] = `
+<div
+ className="source-line-issue-locations">
+ <a
+ className="source-viewer-issue-location issue-location-message selected"
+ href="#"
+ onClick={[Function]} />
+</div>
+`;
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/helpers/indexing.js b/server/sonar-web/src/main/js/components/SourceViewer/helpers/indexing.js
index 13b2926d4ca..b1c79ac0f11 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/helpers/indexing.js
+++ b/server/sonar-web/src/main/js/components/SourceViewer/helpers/indexing.js
@@ -40,7 +40,7 @@ export type IndexedIssueLocation = {
export type IndexedIssueLocationMessage = {
flowIndex: number,
locationIndex: number,
- msg: string
+ msg?: string
};
export type IndexedIssueLocationsByIssueAndLine = {