Skip to content

Commit

Permalink
Fix malformed URI error for search
Browse files Browse the repository at this point in the history
fixes MAT-1151
flag=none

test plan
- Login to canvas and grab token for RCS session
- Make API call to /api/announcements
- Use something for search_term that would cause URI error, like 80%
> Verify search results are as expected, no error returned

Change-Id: Ia97d30dc67bb400bc6ace4a6ac7054c3e28b05c0
Reviewed-on: https://gerrit.instructure.com/c/canvas-rce-api/+/309209
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Deyvison Penha <[email protected]>
QA-Review: Deyvison Penha <[email protected]>
Product-Review: Allison Howell <[email protected]>
  • Loading branch information
jacobdewar committed Jan 26, 2023
1 parent 0a8a30e commit 9b7c82a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.24]

Fix malformed URI error for search

## [1.23]

Response for files list includes file category

## [1.21]

Rename Buttons & Icon text to Icon Maker

## [1.20]

### Added

- Responses from the documents API now include the file's media_entry_id. This ID corresponds to a Canvas MediaObject.
- The files API now accepts query params that communicate to Canvas the "replaced by" chain context

## [1.19]

### Added

- A changelog to make changes more clear

### Changed
- The canvas-rce-api Docker image now uses Node 16 and NPM 8

- The canvas-rce-api Docker image now uses Node 16 and NPM 8
14 changes: 10 additions & 4 deletions app/utils/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ function getSearch(query) {
return "";
}

const isSearchTermEncoded = searchTerm !== decodeURIComponent(searchTerm);
return isSearchTermEncoded
? `&search_term=${searchTerm}`
: `&search_term=${encodeURIComponent(searchTerm)}`;
let encodedTerm;
try {
isSearchTermEncoded = searchTerm !== decodeURIComponent(searchTerm);
encodedTerm = isSearchTermEncoded
? searchTerm
: encodeURIComponent(searchTerm);
} catch {
encodedTerm = encodeURIComponent(searchTerm);
}
return `&search_term=${encodedTerm}`;
}

module.exports = { getSearch };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canvas-rce-api",
"version": "1.23.0",
"version": "1.24.0",
"description": "An API for proxying requests by the RCE to Canvas and other services.",
"engines": {
"node": "^16",
Expand Down
9 changes: 9 additions & 0 deletions test/service/utils/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ describe("search(query)", () => {
`Expected ${getSearchResult} to end with ${encodedSearchText}`
);
});

it("does not return an error for malformed URIs", () => {
const searchTerm = "80%";
const encodedSearchText = encodeURIComponent(searchTerm);
query.search_term = searchTerm;

const getSearchResult = search.getSearch(query);
assert(getSearchResult.endsWith(encodedSearchText));
});
});

0 comments on commit 9b7c82a

Please sign in to comment.