When I pipe the following snippet of PostScript code: %!PS-Adobe << /PageSize [300 300] /MediaType (Square) /cupsMediaType 12345 >> setpagedevice /Helvetica findfont 24 scalefont setfont 10 10 moveto (Hello World) show showpage into "gs -q -sDEVICE=cups -sOutputFile=foo.cups -", the "cupsMediaType" parameter ends up in foo.cups as expected, but "MediaType" is lost. I found out that in cups_put_params, param_read_int returns 0 for "cupsMediaType", but param_read_string returns 1 for "MediaType", so the "MediaType" parameter apparently isn't in the parameter list.
Created attachment 18843 [details] This is the expected result Note that 'strings foo.cups.good' will show the string "Square".
Created attachment 18844 [details] This is what GhostScript produces instead
Ghostscript has a special option for cups: -dNOMEDIAATTRS . This option disables normal media selection and passes media attributes to cups driver, as requested by the bug report. In short, Ghostscript works as designed.
Created attachment 19577 [details] Patch This is a partial clean-up of macros in the cups driver. It helped me to solve this case, and may be worth to adopt to the code base.
Closing as 'works for me' per Peter's comment #3