Fix exception on bad directive '@'

Without this fix the following exception was raised:
NoMethodError: undefined method `gsub' for nil:NilClass

This is adapted to master form PR #1063 which was made against stable.