Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
RewriteRule ^api/volumes/oclc/([0-9]+)[.]html$ index.php?fromoclc=1&module=Record&action=Home&mergesearch=id:1;oclc:$1 [QSA,L]

# API
RewriteRule ^api/volumes/(.*)/(json|html|inlinehtml)/(.*)$ static/api/volumes.php?q=$3&type=$2&brevity=$1 [QSA,L]
RewriteRule ^api/volumes/(full|brief)/([^/]+)/(.+)[.](json|html|oclcscrape) static/api/volumes.php?q=$2:$3&type=$4&single=1&brevity=$1 [QSA,L]
RewriteRule ^api/volumes/(.*)/(json|html|inlinehtml)/(.*)$ static/api/volumes.php?q=$3&type=$2&brevity=$1 [B,QSA,L]
RewriteRule ^api/volumes/(full|brief)/([^/]+)/(.+)[.](json|html|oclcscrape) static/api/volumes.php?q=$2:$3&type=$4&single=1&brevity=$1 [B,QSA,L]

RewriteRule ^api/volumes/(json|html|inlinehtml)/(.*)$ static/api/volumes.php?q=$2&type=$1 [QSA,L]
RewriteRule ^api/volumes/(recordid|sysid|oclc|htid|issn|isbn|lccn|umid)/(.*)[.](.*)$ static/api/volumes.php?q=$1:$2&type=$3&single=1 [QSA,L]
RewriteRule ^api/volumes/(json|html|inlinehtml)/(.*)$ static/api/volumes.php?q=$2&type=$1 [B,QSA,L]
RewriteRule ^api/volumes/(recordid|sysid|oclc|htid|issn|isbn|lccn|umid)/(.*)[.](.*)$ static/api/volumes.php?q=$1:$2&type=$3&single=1 [B,QSA,L]



Expand Down
21 changes: 21 additions & 0 deletions playwright/test/slow/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,24 @@ test('Bib API qf/qv.t htid', async ({ page }) => {
const body = await response.json();
expect(body.items.length).toBeGreaterThan(0);
});

// =========== Input filtering
test('Bib API with spaces in HTID', async ({ page }) => {
const spacey_test_htid = 'mdp.3901 50488 95836';
const response = await page.goto(`/api/volumes/brief/htid/${spacey_test_htid}.json`);
expect(response.status()).toBe(200);
expect(response.headers()["content-type"]).toContain('application/json');
const body = await response.json();
expect(body.records).toHaveProperty(test_cid);
expect(body.items.length).toBeGreaterThan(0);
});

test('Bib API with spaces in recordnumber', async ({ page }) => {
const spacey_test_cid = '0023 12286';
const response = await page.goto(`/api/volumes/brief/recordnumber/${spacey_test_cid}.json`);
expect(response.status()).toBe(200);
expect(response.headers()["content-type"]).toContain('application/json');
const body = await response.json();
expect(body.records).toHaveProperty(test_cid);
expect(body.items.length).toBeGreaterThan(0);
});
16 changes: 9 additions & 7 deletions static/api/volumes.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function __construct($str, $brevity) {
# }
$field = trimlower($fv[0]);

// This user-supplied ID can be anything, it is not sent to Solr.
if ($field == 'id') {
$this->_id = $fv[1];
continue;
Expand All @@ -151,7 +152,6 @@ function __construct($str, $brevity) {

$val = trimlower($fv[1]);

//
// echo "Q is " . $_REQUEST['q'];
// echo "Looking for $field = $val\n";

Expand All @@ -160,14 +160,16 @@ function __construct($str, $brevity) {
continue;
}
$fixedval = $validField[$field]($val); // weird call-variable-value-as-name-of-function

// Escape the colons


# $fixedval = preg_replace('/:/', '\:', $fixedval);
// If our filter left nothing, do not try to send -- Solr is expecting a term.
if (!preg_match('/\S/', $fixedval)) {
continue;
}

// Remove any lurking spaces
$fixedval = preg_replace('/\s+/', '', $fixedval);
$fixedval = $this->lucene_escape($fixedval);
$qfield = isset($fieldmap[$field])? $fieldmap[$field] : $field;

$qfield = isset($fieldmap[$field])? $fieldmap[$field] : $field;

$this->qspecs[] = "$qfield:$fixedval";
if ($qfield == 'lccn') {
Expand Down