MOBILE-3833 core: Add '^' dynamically in link handlers

main
Dani Palou 2022-04-06 15:54:05 +02:00
parent 1fc0b9184b
commit 195c8d94e6
48 changed files with 62 additions and 45 deletions

View File

@ -27,7 +27,7 @@ import { AddonBadges } from '../badges';
export class AddonBadgesBadgeLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonBadgesBadgeLinkHandler';
pattern = /^\/badges\/badge\.php.*([?&]hash=)/;
pattern = /\/badges\/badge\.php.*([?&]hash=)/;
/**
* Get the list of actions for a link (url).

View File

@ -27,7 +27,7 @@ export class AddonBadgesMyBadgesLinkHandlerService extends CoreContentLinksHandl
name = 'AddonBadgesMyBadgesLinkHandler';
featureName = 'CoreUserDelegate_AddonBadges';
pattern = /^\/badges\/mybadges\.php/;
pattern = /\/badges\/mybadges\.php/;
/**
* Get the list of actions for a link (url).

View File

@ -28,7 +28,7 @@ export class AddonBlogIndexLinkHandlerService extends CoreContentLinksHandlerBas
name = 'AddonBlogIndexLinkHandler';
featureName = 'CoreUserDelegate_AddonBlog:blogs';
pattern = /^\/blog\/index\.php/;
pattern = /\/blog\/index\.php/;
/**
* @inheritdoc

View File

@ -30,7 +30,7 @@ const SUPPORTED_VIEWS = ['month', 'mini', 'minithree', 'day', 'upcoming', 'upcom
export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonCalendarViewLinkHandler';
pattern = /^\/calendar\/view\.php/;
pattern = /\/calendar\/view\.php/;
/**
* Get the list of actions for a link (url).

View File

@ -29,6 +29,7 @@ export class AddonCompetencyCompetencyLinkHandlerService extends CoreContentLink
name = 'AddonCompetencyCompetencyLinkHandler';
pattern = /\/admin\/tool\/lp\/(user_competency_in_course|user_competency_in_plan)\.php/;
patternMatchStart = false;
/**
* @inheritdoc

View File

@ -28,6 +28,7 @@ export class AddonCompetencyPlanLinkHandlerService extends CoreContentLinksHandl
name = 'AddonCompetencyPlanLinkHandler';
pattern = /\/admin\/tool\/lp\/plan\.php.*([?&]id=\d+)/;
patternMatchStart = false;
/**
* @inheritdoc

View File

@ -28,6 +28,7 @@ export class AddonCompetencyPlansLinkHandlerService extends CoreContentLinksHand
name = 'AddonCompetencyPlansLinkHandler';
pattern = /\/admin\/tool\/lp\/plans\.php/;
patternMatchStart = false;
/**
* @inheritdoc

View File

@ -28,6 +28,7 @@ export class AddonCompetencyUserCompetencyLinkHandlerService extends CoreContent
name = 'AddonCompetencyUserCompetencyLinkHandler';
pattern = /\/admin\/tool\/lp\/user_competency\.php.*([?&]id=\d+)/;
patternMatchStart = false;
/**
* @inheritdoc

View File

@ -26,7 +26,7 @@ import { AddonMessages } from '../messages';
export class AddonMessagesContactRequestLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonMessagesContactRequestLinkHandler';
pattern = /^\/message\/pendingcontactrequests\.php/;
pattern = /\/message\/pendingcontactrequests\.php/;
/**
* Get the list of actions for a link (url).

View File

@ -29,7 +29,7 @@ import { AddonMessages } from '../messages';
export class AddonMessagesDiscussionLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonMessagesDiscussionLinkHandler';
pattern = /^\/message\/index\.php.*([?&](id|user1|user2)=\d+)/;
pattern = /\/message\/index\.php.*([?&](id|user1|user2)=\d+)/;
/**
* Get the list of actions for a link (url).

View File

@ -28,7 +28,7 @@ import { AddonMessagesMainMenuHandlerService } from './mainmenu';
export class AddonMessagesIndexLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonMessagesIndexLinkHandler';
pattern = /^\/message\/index\.php((?![?&](id|user1|user2)=\d+).)*$/;
pattern = /\/message\/index\.php((?![?&](id|user1|user2)=\d+).)*$/;
/**
* Get the list of actions for a link (url).

View File

@ -28,7 +28,7 @@ export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandl
name = 'AddonModDataApproveLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
pattern = /^\/mod\/data\/view\.php.*([?&](d|approve|disapprove)=\d+)/;
pattern = /\/mod\/data\/view\.php.*([?&](d|approve|disapprove)=\d+)/;
priority = 50; // Higher priority than the default link handler for view.php.
/**

View File

@ -28,7 +28,7 @@ export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandle
name = 'AddonModDataDeleteLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
pattern = /^\/mod\/data\/view\.php.*([?&](d|delete)=\d+)/;
pattern = /\/mod\/data\/view\.php.*([?&](d|delete)=\d+)/;
/**
* @inheritdoc

View File

@ -32,7 +32,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB
name = 'AddonModDataEditLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
pattern = /^\/mod\/data\/edit\.php.*([?&](d|rid)=\d+)/;
pattern = /\/mod\/data\/edit\.php.*([?&](d|rid)=\d+)/;
/**
* @inheritdoc

View File

@ -32,7 +32,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB
name = 'AddonModDataShowLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
pattern = /^\/mod\/data\/view\.php.*([?&](d|rid|page|group|mode)=\d+)/;
pattern = /\/mod\/data\/view\.php.*([?&](d|rid|page|group|mode)=\d+)/;
priority = 50; // Higher priority than the default link handler for view.php.
/**

View File

@ -30,7 +30,7 @@ export class AddonModFeedbackAnalysisLinkHandlerService extends CoreContentLinks
name = 'AddonModFeedbackAnalysisLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /^\/mod\/feedback\/analysis\.php.*([&?]id=\d+)/;
pattern = /\/mod\/feedback\/analysis\.php.*([&?]id=\d+)/;
/**
* @inheritdoc

View File

@ -31,7 +31,7 @@ export class AddonModFeedbackCompleteLinkHandlerService extends CoreContentLinks
name = 'AddonModFeedbackCompleteLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /^\/mod\/feedback\/complete\.php.*([?&](id|gopage)=\d+)/;
pattern = /\/mod\/feedback\/complete\.php.*([?&](id|gopage)=\d+)/;
/**
* @inheritdoc

View File

@ -31,7 +31,7 @@ export class AddonModFeedbackPrintLinkHandlerService extends CoreContentLinksHan
name = 'AddonModFeedbackPrintLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /^\/mod\/feedback\/print\.php.*([?&](id)=\d+)/;
pattern = /\/mod\/feedback\/print\.php.*([?&](id)=\d+)/;
/**
* @inheritdoc

View File

@ -27,7 +27,7 @@ export class AddonModFeedbackShowEntriesLinkHandlerService extends CoreContentLi
name = 'AddonModFeedbackShowEntriesLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /^\/mod\/feedback\/show_entries\.php.*([?&](id|showcompleted)=\d+)/;
pattern = /\/mod\/feedback\/show_entries\.php.*([?&](id|showcompleted)=\d+)/;
/**
* @inheritdoc

View File

@ -30,7 +30,7 @@ export class AddonModFeedbackShowNonRespondentsLinkHandlerService extends CoreCo
name = 'AddonModFeedbackShowNonRespondentsLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /^\/mod\/feedback\/show_nonrespondents\.php.*([?&](id)=\d+)/;
pattern = /\/mod\/feedback\/show_nonrespondents\.php.*([?&](id)=\d+)/;
/**
* @inheritdoc

View File

@ -28,7 +28,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
name = 'AddonModForumDiscussionLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModForum';
pattern = /^\/mod\/forum\/discuss\.php.*([&?]d=\d+)/;
pattern = /\/mod\/forum\/discuss\.php.*([&?]d=\d+)/;
/**
* Get the list of actions for a link (url).

View File

@ -32,7 +32,7 @@ export class AddonModForumPostLinkHandlerService extends CoreContentLinksHandler
name = 'AddonModForumPostLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModForum';
pattern = /^\/mod\/forum\/post\.php.*([?&](forum)=\d+)/;
pattern = /\/mod\/forum\/post\.php.*([?&](forum)=\d+)/;
/**
* Get the list of actions for a link (url).

View File

@ -32,7 +32,7 @@ export class AddonModGlossaryEditLinkHandlerService extends CoreContentLinksHand
name = 'AddonModGlossaryEditLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModGlossary';
pattern = /^\/mod\/glossary\/edit\.php.*([?&](cmid)=\d+)/;
pattern = /\/mod\/glossary\/edit\.php.*([?&](cmid)=\d+)/;
/**
* @inheritdoc

View File

@ -31,7 +31,7 @@ export class AddonModGlossaryEntryLinkHandlerService extends CoreContentLinksHan
name = 'AddonModGlossaryEntryLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModGlossary';
pattern = /^\/mod\/glossary\/(showentry|view)\.php.*([&?](eid|g|mode|hook)=\d+)/;
pattern = /\/mod\/glossary\/(showentry|view)\.php.*([&?](eid|g|mode|hook)=\d+)/;
/**
* @inheritdoc

View File

@ -33,7 +33,7 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink
name = 'AddonModH5PActivityReportLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModH5PActivity';
pattern = /^\/mod\/h5pactivity\/report\.php.*([&?]a=\d+)/;
pattern = /\/mod\/h5pactivity\/report\.php.*([&?]a=\d+)/;
/**
* @inheritdoc

View File

@ -31,7 +31,7 @@ export class AddonModLessonReportLinkHandlerService extends CoreContentLinksHand
name = 'AddonModLessonReportLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModLesson';
pattern = /^\/mod\/lesson\/report\.php.*([&?]id=\d+)/;
pattern = /\/mod\/lesson\/report\.php.*([&?]id=\d+)/;
/**
* Get the list of actions for a link (url).

View File

@ -26,7 +26,7 @@ export class AddonModQuizReviewLinkHandlerService extends CoreContentLinksHandle
name = 'AddonModQuizReviewLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
pattern = /^\/mod\/quiz\/review\.php.*([&?]attempt=\d+)/;
pattern = /\/mod\/quiz\/review\.php.*([&?]attempt=\d+)/;
/**
* Get the list of actions for a link (url).

View File

@ -33,7 +33,7 @@ export class AddonModWikiCreateLinkHandlerService extends CoreContentLinksHandle
name = 'AddonModWikiCreateLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModWiki';
pattern = /^\/mod\/wiki\/create\.php.*([&?]swid=\d+)/;
pattern = /\/mod\/wiki\/create\.php.*([&?]swid=\d+)/;
/**
* Check if the current view is a wiki page of the same wiki.

View File

@ -31,7 +31,7 @@ export class AddonModWikiEditLinkHandlerService extends CoreContentLinksHandlerB
name = 'AddonModWikiEditLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModWiki';
pattern = /^\/mod\/wiki\/edit\.php.*([&?]pageid=\d+)/;
pattern = /\/mod\/wiki\/edit\.php.*([&?]pageid=\d+)/;
/**
* @inheritdoc

View File

@ -32,7 +32,7 @@ export class AddonModWikiPageOrMapLinkHandlerService extends CoreContentLinksHan
name = 'AddonModWikiPageOrMapLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModWiki';
pattern = /^\/mod\/wiki\/(view|map)\.php.*([&?]pageid=\d+)/;
pattern = /\/mod\/wiki\/(view|map)\.php.*([&?]pageid=\d+)/;
/**
* @inheritdoc

View File

@ -27,7 +27,7 @@ import { AddonNotificationsMainMenuHandlerService } from './mainmenu';
export class AddonNotificationsLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonNotificationsLinkHandler';
pattern = /^\/message\/output\/popup\/notifications\.php/;
pattern = /\/message\/output\/popup\/notifications\.php/;
featureName = 'CoreMainMenuDelegate_AddonNotifications';
/**

View File

@ -28,7 +28,7 @@ import { AddonNotificationsSettingsHandlerService } from './settings';
export class AddonNotificationsPreferencesLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonNotificationsPreferencesLinkHandler';
pattern = /^\/message\/notificationpreferences\.php/;
pattern = /\/message\/notificationpreferences\.php/;
checkAllUsers = true;
featureName = 'CoreMainMenuDelegate_AddonNotifications';

View File

@ -38,7 +38,7 @@ const BULK_ACTIONS = {
export class AddonReportInsightsActionLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonReportInsightsActionLinkHandler';
pattern = /^\/report\/insights\/action\.php/;
pattern = /\/report\/insights\/action\.php/;
/**
* @inheritdoc

View File

@ -50,6 +50,11 @@ export class CoreContentLinksHandlerBase implements CoreContentLinksHandler {
*/
pattern?: RegExp;
/**
* If true, a "^" will be added to the beginning of the pattern. It's recommended to avoid collisions with other handlers.
*/
patternMatchStart = true;
/**
* Get the list of actions for a link (url).
*
@ -82,7 +87,15 @@ export class CoreContentLinksHandlerBase implements CoreContentLinksHandler {
* @return Whether the URL is handled by this handler
*/
handles(url: string): boolean {
return !!this.pattern && url.search(this.pattern) >= 0;
let pattern = this.pattern;
if (pattern && this.patternMatchStart) {
let patternString = pattern.toString();
patternString = patternString.substring(1, patternString.length - 1); // Remove slashes from beginning and end.
pattern = new RegExp('^' + patternString);
}
return !!pattern && url.search(pattern) >= 0;
}
/**

View File

@ -47,7 +47,7 @@ export class CoreContentLinksModuleGradeHandler extends CoreContentLinksHandlerB
super();
// Match the grade.php URL with an id param.
this.pattern = new RegExp('^/mod/' + modName + '/grade.php.*([&?]id=\\d+)');
this.pattern = new RegExp('/mod/' + modName + '/grade.php.*([&?]id=\\d+)');
this.featureName = 'CoreCourseModuleDelegate_' + addon;
}

View File

@ -45,8 +45,8 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB
// Match the view.php URL with an id or instance id param.
const pattern = instanceIdParam ?
'^/mod/' + modName + '/view.php.*([&?](' + instanceIdParam + '|id)=\\d+)' :
'^/mod/' + modName + '/view.php.*([&?]id=\\d+)';
'/mod/' + modName + '/view.php.*([&?](' + instanceIdParam + '|id)=\\d+)' :
'/mod/' + modName + '/view.php.*([&?]id=\\d+)';
this.pattern = new RegExp(pattern);
this.featureName = 'CoreCourseModuleDelegate_' + addon;

View File

@ -41,7 +41,7 @@ export class CoreContentLinksModuleListHandler extends CoreContentLinksHandlerBa
super();
// Match the index.php URL with an id param.
this.pattern = new RegExp('^/mod/' + modName + '/index.php.*([&?]id=\\d+)');
this.pattern = new RegExp('/mod/' + modName + '/index.php.*([&?]id=\\d+)');
this.featureName = 'CoreCourseModuleDelegate_' + addon;
}

View File

@ -35,7 +35,7 @@ import { CoreIonLoadingElement } from '@classes/ion-loading';
export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreCoursesCourseLinkHandler';
pattern = /((^\/enrol\/index\.php)|(^\/course\/enrol\.php)|(^\/course\/view\.php)).*([?&]id=\d+)/;
pattern = /((\/enrol\/index\.php)|(\/course\/enrol\.php)|(\/course\/view\.php)).*([?&]id=\d+)/;
protected waitStart = 0;
protected logger: CoreLogger;

View File

@ -28,7 +28,7 @@ export class CoreCoursesIndexLinkHandlerService extends CoreContentLinksHandlerB
name = 'CoreCoursesIndexLinkHandler';
featureName = 'CoreMainMenuDelegate_CoreCourses';
pattern = /^\/course\/?(index\.php.*)?$/;
pattern = /\/course\/?(index\.php.*)?$/;
/**
* @inheritdoc

View File

@ -27,7 +27,7 @@ import { CoreDashboardHomeHandler, CoreDashboardHomeHandlerService } from './das
export class CoreCoursesDashboardLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreCoursesDashboardLinkHandler';
pattern = /^\/my\/?$/;
pattern = /\/my\/?$/;
/**
* Get the list of actions for a link (url).

View File

@ -27,7 +27,7 @@ import { GRADES_PAGE_NAME } from '../grades-helper';
export class CoreGradesOverviewLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreGradesOverviewLinkHandler';
pattern = /^\/grade\/report\/overview\/index.php/;
pattern = /\/grade\/report\/overview\/index.php/;
/**
* Get the list of actions for a link (url).

View File

@ -27,7 +27,7 @@ import { makeSingleton } from '@singletons';
export class CoreGradesReportLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreGradesReportLinkHandler';
pattern = /^\/grade\/report(\/user)?\/index.php/;
pattern = /\/grade\/report(\/user)?\/index.php/;
/**
* Get the list of actions for a link (url).

View File

@ -27,7 +27,7 @@ import { makeSingleton } from '@singletons';
export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreGradesUserLinkHandler';
pattern = /^\/course\/user\.php.*[?&]mode=grade/;
pattern = /\/course\/user\.php.*[?&]mode=grade/;
/**
* Get the list of actions for a link (url).

View File

@ -31,7 +31,7 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler
name = 'CoreSiteHomeIndexLinkHandler';
featureName = 'CoreMainMenuDelegate_CoreSiteHome';
pattern = /^\/course\/view\.php.*([?&]id=\d+)|^\/index\.php(\?redirect=0)?/;
pattern = /(\/course\/view\.php.*([?&]id=\d+)|\/index\.php(\?redirect=0)?)/;
/**
* @inheritdoc

View File

@ -27,7 +27,7 @@ import { CoreTag } from '../tag';
export class CoreTagIndexLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreTagIndexLinkHandler';
pattern = /^\/tag\/index\.php/;
pattern = /\/tag\/index\.php/;
/**
* Get the list of actions for a link (url).

View File

@ -27,7 +27,7 @@ import { CoreTag } from '../tag';
export class CoreTagSearchLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'CoreTagSearchLinkHandler';
pattern = /^\/tag\/search\.php/;
pattern = /\/tag\/search\.php/;
/**
* Get the list of actions for a link (url).

View File

@ -27,7 +27,7 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa
name = 'CoreUserProfileLinkHandler';
// Match user/view.php and user/profile.php but NOT grade/report/user/.
pattern = /((^\/user\/view\.php)|(^\/user\/profile\.php)).*([?&]id=\d+)/;
pattern = /((\/user\/view\.php)|(\/user\/profile\.php)).*([?&]id=\d+)/;
/**
* Get the list of actions for a link (url).

View File

@ -24,7 +24,7 @@ information provided here is intended especially for developers.
- contextMenuPrefetch and fillContextMenu have been removed from CoreCourseHelper.
- The variable "loaded" in CoreCourseModuleMainResourceComponent has been changed to "showLoading" to reflect its purpose better.
- The function getCurrentSection of course formats can now return a forceSelected boolean along with the section (defaults to false if not returned).
- The link handlers functions (CoreContentLinksHandler) will now always receive a relative URL instead of an absolute URL. It's now recommended to use "^" in your regular expressions to avoid false positives.
- The link handlers functions (CoreContentLinksHandler) will now always receive a relative URL instead of an absolute URL. The CoreContentLinksHandlerBase class now adds "^" to the start of the pattern by default to prevent false positives.