Skip to content

[Bug] CalendarFetcherUtils.js, excludedEvents:["string"] not working #3841

@sdetweil

Description

@sdetweil

Environment

SYSTEM: manufacturer: System manufacturer; model: System Product Name; virtual: false

OS: platform: linux; distro: Ubuntu; release: 22.04.5 LTS; arch: x64; kernel: 5.15.0-142-generic

VERSIONS: electron: 36.6.0; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.2; pm2: 6.0.8

OTHER: timeZone: America/Chicago; ELECTRON_ENABLE_GPU: undefined

Which start option are you using?

node --run start

Are you using PM2?

No

Module

calendar

Have you tried disabling other modules?

  • Yes
  • No

Have you searched if someone else has already reported the issue on the forum or in the issues?

  • Yes

What did you do?

		{
			module: "calendar",
			header: "US Holidays",
			position: "top_left",
			config: {
                                excludedEvents;["birthday"],
				calendars: [
					{
						fetchInterval: 7 * 24 * 60 * 60 * 1000,
						symbol: "calendar-check",
						url: "https://ics.calendarlabs.com/76/mm3137/US_Holidays.ics"  // apply appropriate url 
					}
				]
			}
		},

What did you expect to happen?

expected events with 'birthday' in the title to not be shown

What actually happened?

they were shown

reference https://forum.magicmirror.builders/topic/19767/2.32.0-calendar-module-limitdays-and-excludedevents-stopped-working?page=1

Additional comments

shouldEventBeExcluded (config, title) {
		let filter = {
			excluded: false,
			until: null
		};
		for (let f in config.excludedEvents) {
			let filter = config.excludedEvents[f],   // second var 'filter', inside for loop  scope
				testTitle = title.toLowerCase(),
				until = null,
				useRegex = false,
				regexFlags = "g";

			if (filter instanceof Object) {
				if (typeof filter.until !== "undefined") {
					until = filter.until;
				}

				if (typeof filter.regex !== "undefined") {
					useRegex = filter.regex;
				}

				// If additional advanced filtering is added in, this section
				// must remain last as we overwrite the filter object with the
				// filterBy string
				if (filter.caseSensitive) {
					filter = filter.filterBy;
					testTitle = title;
				} else if (useRegex) {
					filter = filter.filterBy;
					testTitle = title;
					regexFlags += "i";
				} else {
					filter = filter.filterBy.toLowerCase();
				}
			} else {
				filter = filter.toLowerCase();   // use this is filter is just a string
			}
			if (CalendarFetcherUtils.titleFilterApplies(testTitle, filter, useRegex, regexFlags)) {				
				if (until) {    
					filter.until = until;  // filter inside for loop is a string
				} else {
					filter.excluded = true;
				}
				break;
			}
		}  //  variables inside for loop are now out of scope
		return filter;  // oops returns inital 
	},

should change to

shouldEventBeExcluded (config, title) {
		let result = {  // change name 
			excluded: false,
			until: null
		};
		for (let f in config.excludedEvents) {
			let filter = config.excludedEvents[f],
				testTitle = title.toLowerCase(),
				until = null,
				useRegex = false,
				regexFlags = "g";

			if (filter instanceof Object) {
				if (typeof filter.until !== "undefined") {
					until = filter.until;
				}

				if (typeof filter.regex !== "undefined") {
					useRegex = filter.regex;
				}

				// If additional advanced filtering is added in, this section
				// must remain last as we overwrite the filter object with the
				// filterBy string
				if (filter.caseSensitive) {
					filter = filter.filterBy;
					testTitle = title;
				} else if (useRegex) {
					filter = filter.filterBy;
					testTitle = title;
					regexFlags += "i";
				} else {
					filter = filter.filterBy.toLowerCase();
				}
			} else {
				filter = filter.toLowerCase();
			}
			Log.debug("should be excluded ", testTitle, filter, useRegex, regexFlags)
			if (CalendarFetcherUtils.titleFilterApplies(testTitle, filter, useRegex, regexFlags)) {				
				if (until) {
					result.until = until;  // change assignment
				} else {
					Log.debug("event should be excluded = true,", testTitle )
					result.excluded = true;  // change assignment
				}
				Log.debug("filter applies result =", result)
				break;
			}
		}
		Log.debug("filter applies returning =", result)
		return result;  // return outer
	},

Participation

  • I am willing to submit a pull request for this change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions