Validate publication dataset name, primary dataset name and request name. Fixes #4257.

This pull request also generalizes the pull request #4262 from @qunox (which now can be closed), presumably fixing #4255 (I say presumably, because @qunox wrote in his pull request that it was fixing this issue).