Skip to content

Commit

Permalink
116402: Merge 'issue-9690_w2p-116402_apostrophe-in-controlled-vocab-7…
Browse files Browse the repository at this point in the history
….4' into 'issue-9690_w2p-116402_apostrophe-in-controlled-vocab-7.6'
  • Loading branch information
Zahraa Chreim committed Jul 15, 2024
2 parents e893a8b + 89fadab commit 76ceb29
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ public Choices getBestMatch(String text, String locale) {
return new Choices(choices.toArray(new Choice[choices.size()]), 0, choices.size(), Choices.CF_AMBIGUOUS, false);
}

/**
* - If the string doesn't contain any single quotes, it wraps the string in single quotes.
* - If the string contains single quotes but no double quotes, it wraps the string in double quotes.
* - If the string contains both single and double quotes,
* it constructs an XPath expression using the concat function.
* The goal is to allow the string to be safely used in XPath expressions regardless of the presence of quotes.
* @param text
* @return
*/
private String escapeQuotes(String text) {
// If we don't have any quote then enquote string in single quote
if (!text.contains("'")) {
Expand All @@ -228,7 +237,7 @@ private String escapeQuotes(String text) {
sb.append(",");
}

sb.append(String.format("\"%s\",'\"'", text.substring(lastPos, nextPos - lastPos)));
sb.append(String.format("\"%s\",'\"'", text.substring(lastPos, nextPos)));
lastPos = ++nextPos;

// Find next occurrence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@
<node id="VR11390777" label="test&quot;test'example'">
<hasNote>Datorlingvistik</hasNote>
</node>
<node id="VR11390777b" label="test2&quot;test'example&quot;'&quot;test">
<hasNote>Datorlingvistik</hasNote>
</node>
<node id="VR11390777b" label="University's s&quot;P&quot;apers">
<hasNote>Datorlingvistik</hasNote>
</node>
<node id="VR11390888" label="test:example">
<hasNote>Datorlingvistik</hasNote>
</node>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@
<node id="VR11390777" label="test&quot;test'example'">
<hasNote>Datorlingvistik</hasNote>
</node>
<node id="VR11390777b" label="test2&quot;test'example&quot;'&quot;test">
<hasNote>Datorlingvistik</hasNote>
</node>
<node id="VR11390777b" label="University's s&quot;P&quot;apers">
<hasNote>Datorlingvistik</hasNote>
</node>
<node id="VR11390888" label="test:example">
<hasNote>Datorlingvistik</hasNote>
</node>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,45 @@ public void testSearchWithComma() throws Exception {
}

@Test
public void testSearchWithColumn() throws Exception {
public void testSearchWithColon() throws Exception {
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/submission/vocabularies/srsc/entries?filter=test:example&exact=true"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("test:example"));
}

@Test
public void testSearchWithApostropheAndQuoteReversed() throws Exception {
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(
get("/api/submission/vocabularies/srsc/entries?filter=test2\"test'example\"'\"" +
"&exact==false"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("test2\"test'example\"'\"test"));
getClient(tokenAdmin).perform(
get("/api/submission/vocabularies/srsc/entries?filter=test2\"test'exam" +
"&exact==false"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("test2\"test'example\"'\"test"));
getClient(tokenAdmin).perform(
get("/api/submission/vocabularies/srsc/entries?filter=test2\"test'exam" +
"&exact==true"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("test2\"test'example\"'\"test"));
getClient(tokenAdmin).perform(
get("/api/submission/vocabularies/srsc/entries?filter=University's s\"" +
"&exact==false"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("University's s\"P\"apers"));
getClient(tokenAdmin).perform(
get("/api/submission/vocabularies/srsc/entries?filter=University's s\"P\"" +
"&exact==false"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("University's s\"P\"apers"));
getClient(tokenAdmin).perform(
get("/api/submission/vocabularies/srsc/entries?filter=University's s\"P\"apers" +
"&exact==true"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.entries[0].display").value("University's s\"P\"apers"));
}
}

0 comments on commit 76ceb29

Please sign in to comment.