anchor.diff:      {Port, {data, _}} ->
         loop_until_vim_is_done(Filename, Port);
       {Port, {exit_status, 0}} ->
  -      {ok, Highlighted} = file:read_file(Filename),
  +      {ok, VimResult} = file:read_file(Filename),
         file:delete(Filename),
  -      Highlighted;
  +      VimResult;
       _ ->
         error
     end.
  
positive.code:   "'VIREXSTARTH' : '<span class=''highlight''>', 'VIREXSTOPH' : \\\"<\\/" ++
    "span>\\\", 'VIREXBR' : '<br>&#92;'}[submatch(0)]/g \"").
  
  handle_regex(Text, Pattern) ->
    Filename = mktemp(),
    file:write_file(Filename, Text),
    case substitution_command(Filename, Pattern) of
      rejected ->
        <<"Your pattern has been rejected. Please email me with your use case.">>;
      {ok, VimCommand} ->
        Port = open_port({spawn, VimCommand}, [exit_status, stderr_to_stdout]),
        loop_until_vim_is_done(Filename, Port)
    end.
  
  
  substitution_command(Filename, Pattern) ->
    case secure_pattern(Filename, Pattern) of
      rejected ->
        rejected;
      SafePattern ->
        Substitute = " -c \"%s/" ++ SafePattern ++ ?SUBSTITUTION ++ ?HTMLFORMAT,
        {ok, "vim -X " ++ Filename ++ Substitute ++ " -c \"x\""}
    end.
  
  
  secure_pattern(Filename, Pattern) when erlang:length(Pattern) > 80 ->
    reject_pattern(Filename);
  secure_pattern(Filename, Pattern) ->
    case safe(Pattern) of
      true ->
        escape_pattern_quotes(Pattern);
      false ->
        reject_pattern(Filename)
    end.
  
  
  safe(Pattern) ->
    DangerousRegex = "\{-?[0-9]{3,}|[0-9]{3,}\\\\?\}|([^\\\\]|^)(\\\\\\\\)*/",
    re:run(Pattern, DangerousRegex) =:= nomatch.
  
  
  reject_pattern(Filename) ->
    file:delete(Filename),
    rejected.
  
  
  escape_pattern_quotes(Pattern) ->
  
negative.code: 
  mktemp() ->
    string:strip(os:cmd("mktemp -t virextmp.XXXXXXX"), both, $\n).
  
  create_test_file(TestString) ->
    Filename = mktemp(),
    file:write_file(Filename, TestString),
    Filename.
  