Skip to content

Commit

Permalink
#47: Convert id-subcomponent separator from '/' to '.'.
Browse files Browse the repository at this point in the history
The use of '/' as a separator in subcomponents turned out to be a bad idea
because these slashes need to be escaped as %2F, but these escaped slashes
can interfere with some webserver configuration.

For example Apache redirects require the NE "No Escape" option to preserve
%2F slashes without double-escaping:

    # Redirect all traffic to https
    #
    # We're using mod_rewrite here rather than mod_alias's `Redirect`
    # because mod_alias doesn't allow the "NE" == "noescape" parameter
    # that allows URLs includinging encoded slashes (%2F) to be returned
    # without double-escaping.
    RewriteRule .* https://<%= node["app_domain"] %>$0 [L,R=301,NE]

Similarly, Symfony refuses to allow slashes in parameters passed as tokens
in routes.

To address this problematic choice, use '.' as a separator of
sub-components in identifiers. Periods don't require special escaping in
URLs or database queries, though they do in regular expressions.
  • Loading branch information
adamfranco committed Sep 27, 2024
1 parent 3357430 commit 8336afc
Show file tree
Hide file tree
Showing 95 changed files with 765 additions and 758 deletions.
10 changes: 5 additions & 5 deletions application/controllers/ArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,9 @@ protected function getCourseData(osid_course_Course $course)
// Look for different Section Descriptions
$offeringQuery = $this->offeringSearchSession->getCourseOfferingQuery();
$offeringQuery->matchCourseId($course->getId(), true);
$offeringQuery->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:offering/LCT'), true);
$offeringQuery->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:offering/SEM'), true);
$offeringQuery->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:offering/IND'), true);
$offeringQuery->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:offering.LCT'), true);
$offeringQuery->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:offering.SEM'), true);
$offeringQuery->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:offering.IND'), true);
foreach ($this->selectedTerms as $termId) {
$offeringQuery->matchTermId($termId, true);
}
Expand All @@ -856,7 +856,7 @@ protected function getCourseData(osid_course_Course $course)
$instructorsType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:instructors');
$identifiersType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:banner_identifiers');
$namesType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:person_names');
$requirementType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/requirement');
$requirementType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement');
$enrollmentNumbersType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:enrollment_numbers');
while ($offerings->hasNext()) {
$offering = $offerings->getNextCourseOffering();
Expand Down Expand Up @@ -1028,7 +1028,7 @@ protected function getCourseData(osid_course_Course $course)
// Apply all course-level topics.
$allTopics = $this->_helper->topics->topicListAsArray($course->getTopics());
$reqs = [];
$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/requirement');
$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement');
$topicTypeString = $this->_helper->osidType->toString($topicType);
$topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType);
foreach ($topics as $topic) {
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/CoursesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function viewAction()
public function viewxmlAction()
{
$this->_helper->layout->disableLayout();
$this->getResponse()->setHeader('Content-Type', 'text/xml');
$this->getResponse()->setHeader('Content-Type', 'text.xml');

$this->viewAction();
}
Expand Down Expand Up @@ -455,8 +455,8 @@ public function instructorxmlAction()
throw new InvalidArgumentException('An instructor must be specified.');
}

$instructorId = $this->_helper->osidId->fromString('resource/person/'.$instructor);
$searchUrl = $this->_helper->pathAsAbsoluteUrl($this->_helper->url('view', 'resources', null, ['catalog' => $this->_getParam('catalog'), 'resource' => 'resouce/person/'.$instructor]));
$instructorId = $this->_helper->osidId->fromString('resource.person.'.$instructor);
$searchUrl = $this->_helper->pathAsAbsoluteUrl($this->_helper->url('view', 'resources', null, ['catalog' => $this->_getParam('catalog'), 'resource' => 'resouce.person.'.$instructor]));

$resourceLookup = $this->_helper->osid->getCourseManager()->getResourceManager()->getResourceLookupSession();
try {
Expand Down Expand Up @@ -610,7 +610,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse
}

$allTopics = $this->_helper->topics->topicListAsArray($course->getTopics());
$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/department');
$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department');
$topicTypeString = $this->_helper->osidType->toString($topicType);
$topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType);
foreach ($topics as $topic) {
Expand All @@ -620,7 +620,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse
echo '</catalog:topic> ';
}

$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/requirement');
$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement');
$topicTypeString = $this->_helper->osidType->toString($topicType);
$topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType);
foreach ($topics as $topic) {
Expand All @@ -630,7 +630,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse
echo '</catalog:topic> ';
}

$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/level');
$topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.level');
$topicTypeString = $this->_helper->osidType->toString($topicType);
$topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType);
foreach ($topics as $topic) {
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ public function generatecourselistAction()

if ($request->getParam('catalogId')) {
$catalogId = $this->_helper->osidId->fromString($request->getParam('catalogId'));
$this->departmentType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/department');
$this->subjectType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/subject');
$this->departmentType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department');
$this->subjectType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.subject');

$topicSearchSession = $this->_helper->osid->getCourseManager()->getTopicSearchSessionForCatalog($catalogId);
$topicQuery = $topicSearchSession->getTopicQuery();
Expand Down Expand Up @@ -533,7 +533,7 @@ public function validtermAction()
$this->termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId);

try {
$termString = 'term/'.$request->getParam('term');
$termString = 'term.'.$request->getParam('term');
$termId = $this->_helper->osidId->fromString($termString);
} catch (osid_InvalidArgumentException $e) {
header('HTTP/1.1 400 Bad Request');
Expand Down
30 changes: 15 additions & 15 deletions application/controllers/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function init()
public function termsAction()
{
if ($this->_getParam('catalog')) {
$catalogId = $this->_helper->osidId->fromString('catalog/'.$this->_getParam('catalog'));
$catalogId = $this->_helper->osidId->fromString('catalog.'.$this->_getParam('catalog'));
$lookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId);
$currentTermId = $this->_helper->osidTerms->getNextOrLatestTermId($catalogId);
} else {
Expand All @@ -52,7 +52,7 @@ public function termsAction()
if ($currentTermId) {
$term = $lookupSession->getTerm($currentTermId);
$result['terms'][] = [
'code' => preg_replace('/^term\//', '', $term->getId()->getIdentifier()),
'code' => preg_replace('/^term\./', '', $term->getId()->getIdentifier()),
'description' => $term->getDisplayName(),
];
}
Expand All @@ -63,7 +63,7 @@ public function termsAction()
continue;
}
$result['terms'][] = [
'code' => preg_replace('/^term\//', '', $term->getId()->getIdentifier()),
'code' => preg_replace('/^term\./', '', $term->getId()->getIdentifier()),
'description' => $term->getDisplayName(),
];
}
Expand All @@ -83,7 +83,7 @@ public function termsAction()
public function areasAction()
{
if ($this->_getParam('catalog')) {
$catalogId = $this->_helper->osidId->fromString('catalog/'.$this->_getParam('catalog'));
$catalogId = $this->_helper->osidId->fromString('catalog.'.$this->_getParam('catalog'));
$termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId);
$topicSearchSession = $this->_helper->osid->getCourseManager()->getTopicSearchSessionForCatalog($catalogId);
} else {
Expand All @@ -97,10 +97,10 @@ public function areasAction()
if (empty($code)) {
throw new InvalidArgumentException('Missing the "code" parameter.');
}
$termId = $this->_helper->osidId->fromString('term/'.$code);
$termId = $this->_helper->osidId->fromString('term.'.$code);
$term = $termLookupSession->getTerm($termId);

$genera = 'topic/subject';
$genera = 'topic.subject';
$generaType = $this->_helper->osidType->fromString('genera:'.$genera);
$termType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:terms');

Expand All @@ -121,7 +121,7 @@ public function areasAction()
while ($topics->hasNext()) {
$topic = $topics->getNextTopic();
$result['areas'][] = [
'area' => preg_replace('/^'.str_replace('/', '\/', $genera).'\//', '', $topic->getId()->getIdentifier()),
'area' => preg_replace('/^'.str_replace('.', '\.', $genera).'\./', '', $topic->getId()->getIdentifier()),
'name' => $topic->getDisplayName(),
];
}
Expand All @@ -141,7 +141,7 @@ public function areasAction()
public function catalogAction()
{
if ($this->_getParam('catalog')) {
$catalogId = $this->_helper->osidId->fromString('catalog/'.$this->_getParam('catalog'));
$catalogId = $this->_helper->osidId->fromString('catalog.'.$this->_getParam('catalog'));
$searchSession = $this->_helper->osid->getCourseManager()->getCourseSearchSessionForCatalog($catalogId);
$termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId);
$topicLookupSession = $this->_helper->osid->getCourseManager()->getTopicLookupSessionForCatalog($catalogId);
Expand All @@ -158,18 +158,18 @@ public function catalogAction()
$offeringLookupSession->useFederatedCourseCatalogView();

// Validate our arguments.
$genera = 'topic/subject';
$genera = 'topic.subject';
$area = $this->_getParam('area');
if (empty($area)) {
throw new InvalidArgumentException('Missing the "area" parameter.');
}
$topicId = $this->_helper->osidId->fromString($genera.'/'.$area);
$topicId = $this->_helper->osidId->fromString($genera.'.'.$area);
$topic = $topicLookupSession->getTopic($topicId);
$code = $this->_getParam('code');
if (empty($code)) {
throw new InvalidArgumentException('Missing the "code" parameter.');
}
$termId = $this->_helper->osidId->fromString('term/'.$this->_getParam('code'));
$termId = $this->_helper->osidId->fromString('term.'.$this->_getParam('code'));
$term = $termLookupSession->getTerm($termId);

// Build the query.
Expand Down Expand Up @@ -200,7 +200,7 @@ public function catalogAction()
public function searchAction()
{
if ($this->_getParam('catalog')) {
$catalogId = $this->_helper->osidId->fromString('catalog/'.$this->_getParam('catalog'));
$catalogId = $this->_helper->osidId->fromString('catalog.'.$this->_getParam('catalog'));
$searchSession = $this->_helper->osid->getCourseManager()->getCourseOfferingSearchSessionForCatalog($catalogId);
$termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId);
$topicLookupSession = $this->_helper->osid->getCourseManager()->getTopicLookupSessionForCatalog($catalogId);
Expand Down Expand Up @@ -229,15 +229,15 @@ public function searchAction()
if (empty($code)) {
throw new InvalidArgumentException('Missing the "code" parameter.');
}
$termId = $this->_helper->osidId->fromString('term/'.$this->_getParam('code'));
$termId = $this->_helper->osidId->fromString('term.'.$this->_getParam('code'));
$term = $termLookupSession->getTerm($termId);

$query->matchTermId($termId, true);

$genera = 'topic/subject';
$genera = 'topic.subject';
$area = $this->_getParam('area');
if (!empty($area)) {
$topicId = $this->_helper->osidId->fromString($genera.'/'.$area);
$topicId = $this->_helper->osidId->fromString($genera.'.'.$area);
$topic = $topicLookupSession->getTopic($topicId);
$query->matchTopicId($topicId, true);
}
Expand Down
16 changes: 8 additions & 8 deletions application/controllers/OfferingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ public function init()

parent::init();

$this->subjectType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/subject');
$this->departmentType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/department');
$this->divisionType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/division');
$this->requirementType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/requirement');
$this->levelType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/level');
$this->blockType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/block');
$this->instructionMethodType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/instruction_method');
$this->subjectType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.subject');
$this->departmentType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department');
$this->divisionType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.division');
$this->requirementType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement');
$this->levelType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.level');
$this->blockType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.block');
$this->instructionMethodType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.instruction_method');

$this->termType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:terms');

$this->campusType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:resource/place/campus');
$this->campusType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:resource.place.campus');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/ResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function viewAction()
*/
public function listcampusestxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:resource/place/campus'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:resource.place.campus'));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function viewxmlAction()
*/
public function listsubjectstxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/subject'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.subject'));
}

/**
Expand All @@ -253,7 +253,7 @@ public function listsubjectstxtAction()
*/
public function listrequirementstxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/requirement'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement'));
}

/**
Expand All @@ -265,7 +265,7 @@ public function listrequirementstxtAction()
*/
public function listlevelstxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/level'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.level'));
}

/**
Expand All @@ -277,7 +277,7 @@ public function listlevelstxtAction()
*/
public function listblockstxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/block'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.block'));
}

/**
Expand All @@ -289,7 +289,7 @@ public function listblockstxtAction()
*/
public function listinstructionmethodstxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/instruction_method'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.instruction_method'));
}

/**
Expand All @@ -301,7 +301,7 @@ public function listinstructionmethodstxtAction()
*/
public function listdepartmentstxtAction()
{
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic/department'));
$this->renderTextList(new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department'));
}

/**
Expand Down
Loading

0 comments on commit 8336afc

Please sign in to comment.