Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unescaped line termination characters from string literals if needed #61

Closed
wants to merge 2 commits into from

Conversation

metalblue
Copy link

If the printer isn't sleeping then the status1 field frequently contains unescaped new line characters which causes the demjson3 to generate an exception.

This PR attempts to escape these new line characters if the initial parsing fails before trying to reparse the json.

@nielstron
Copy link
Owner

Thanks for adding this :) Please add a test case for the printer behaviour. Alternatively just share the raw data returned by the sleeping printer with this unescaped newline

@metalblue
Copy link
Author

Here is the raw data (with a few values obfuscated) with the unescaped newline:

{
	status: {
		hrDeviceStatus: 3,
		status1: "   Warming Up   
 Please Wait... 


",
		status2: "",
		status3: "",
		status4: ""
	},
	identity: {
		model_name: "C480FW",
		device_name: "Samsung C480FW",
		host_name: "PRINTER",
		location: "Office",
		serial_num: "xxxxxxxxxxxxxxxxxx",
		ip_addr: "xx.xx.xx.xx",
		ipv6_link_addr : "",
		mac_addr: "xx:xx:xx:xx:xx:xx",
		admin_email: "mail@example.com",
		admin_name: "Admin
		admin_phone: "",
		customer_support: ""
	},

	toner_black: {
		opt: 1,
		remaining: 78,
		cnt: 330,
		newError: ""
	},
	toner_cyan: {
		opt: 1,
		remaining: 25,
		cnt: 563,
		newError: ""
	},
	toner_magenta: {
		opt: 1,
		remaining: 33,
		cnt: 567,
		newError: ""
	},
	toner_yellow: {
		opt: 1,
		remaining: 0,
		cnt: 569,
		newError: "C1-2150"
	},

	drum_black: {
		opt: 0,
		remaining: 84,
		newError: ""
	},
	drum_cyan: {
		opt: 0,
		remaining: 100,
		newError: ""
	},
	drum_magenta: {
		opt: 0,
		remaining: 100,
		newError: ""
	},
	drum_yellow: {
		opt: 0,
		remaining: 100,
		newError: ""
	},
	drum_color: {
		opt: 1,
		remaining: 84,
		newError: ""
	},
	
	tray1: {
		opt: 1,
		paper_size1: 1,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		paper_level: 0,
		capa: 150,
		newError: ""
	},
	tray2: {
		opt: 0,
		paper_size1: 0,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		paper_level: 0,
		capa: 0,
		newError: ""
	},
	tray3: {
		opt: 0,
		paper_size1: 0,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		paper_level: 0,
		capa: 0,
		newError: ""
	},
	tray4: {
		opt: 0,
		paper_size1: 0,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		paper_level: 0,
		capa: 0,
		newError: ""
	},
	tray5: {
		opt: 0,
		paper_size1: 0,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		paper_level: 0,
		capa: 0,
		newError: "0"
	},
	mp: {
		opt: 0,
		paper_size1: 0,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		paper_level: 0,
		capa: 0,
		newError: ""
	},
	manual: {
		opt: 0,
		paper_size1: 0,
		paper_size2: 0,
		paper_type1: 2,
		paper_type2: 0,
		capa: 0,
		newError: ""
	},	
	GXI_INTRAY_MANUALFEEDING_TRAY_SUPPORT: 0,
	GXI_INSTALL_OPTION_MULTIBIN:0,
	multibin: [
		0
	],
	outputTray: [
		[1, 50, ""]
	],
	capability: {
		hdd: {opt: 2, capa: 40},
		ram: {opt: 131072, capa: 131072},
		scanner: {opt: 40 , capa: 40}
	},

	options: {
		fax: 1,hdd: 0,wlan: 1,adf: 1
	},
	GXI_ACTIVE_ALERT_TOTAL: 1,
	GXI_ADMIN_WUI_HAS_DEFAULT_PASS: 0,
	GXI_SUPPORT_COLOR: 1,
	GXI_SYS_LUI_SUPPORT: 1,
	GXI_A3_SUPPORT: 0,
	GXI_TRAY2_MANDATORY_SUPPORT: 0,
	GXI_SWS_ADMIN_USE_AAA:0,
	GXI_TONER_BLACK_VALID: 1,
	GXI_TONER_CYAN_VALID: 1,
	GXI_TONER_MAGENTA_VALID: 1,
	GXI_TONER_YELLOW_VALID: 1,
	GXI_IMAGING_BLACK_VALID: 1,
	GXI_IMAGING_CYAN_VALID: 1,
	GXI_IMAGING_MAGENTA_VALID: 1,
	GXI_IMAGING_YELLOW_VALID: 1,
	GXI_IMAGING_COLOR_VALID: 1,
	GXI_SUPPORT_PAPER_SETTING: 1,
	GXI_SUPPORT_PAPER_LEVEL: 0,
	GXI_SUPPORT_MULTI_PASS : 1
}

@metalblue
Copy link
Author

Should have said. when the printer is "Sleeping" the status1 always appears to be Sleeping... and there isn't an issue. Its when the printer isn't sleeping that I see the issue.

@erkr
Copy link

erkr commented May 6, 2023

For me that same behaviour. Only see these errors when using the printer

@metalblue
Copy link
Author

@nielstron any chance this PR could be approved?

@nielstron
Copy link
Owner

Yes totally. There should be a new testcase though based on the raw data you shared. I can have a look if I can add it myself.

@erkr
Copy link

erkr commented Nov 7, 2023

Yes please, 🙏

@nielstron nielstron mentioned this pull request Nov 14, 2023
@nielstron
Copy link
Owner

superseded by #62

@nielstron nielstron closed this Nov 14, 2023
@erkr
Copy link

erkr commented Nov 15, 2023

Thanks. Looking forward for the HA Release with this fix 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants