Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8 KiB

  1. package URI::_query;
  2. use strict;
  3. use URI ();
  4. use URI::Escape qw(uri_unescape);
  5. sub query
  6. {
  7. my $self = shift;
  8. $$self =~ m,^([^?\#]*)(?:\?([^\#]*))?(.*)$,s or die;
  9. if (@_) {
  10. my $q = shift;
  11. $$self = $1;
  12. if (defined $q) {
  13. $q =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
  14. $$self .= "?$q";
  15. }
  16. $$self .= $3;
  17. }
  18. $2;
  19. }
  20. # Handle ...?foo=bar&bar=foo type of query
  21. sub query_form {
  22. my $self = shift;
  23. my $old = $self->query;
  24. if (@_) {
  25. # Try to set query string
  26. my @query;
  27. while (my($key,$vals) = splice(@_, 0, 2)) {
  28. $key = '' unless defined $key;
  29. $key =~ s/([;\/?:@&=+,\$%])/$URI::Escape::escapes{$1}/g;
  30. $key =~ s/ /+/g;
  31. $vals = [ref($vals) ? @$vals : $vals];
  32. for my $val (@$vals) {
  33. $val = '' unless defined $val;
  34. $val =~ s/([;\/?:@&=+,\$%])/$URI::Escape::escapes{$1}/g;
  35. $val =~ s/ /+/g;
  36. push(@query, "$key=$val");
  37. }
  38. }
  39. $self->query(join('&', @query));
  40. }
  41. return if !defined($old) || !length($old) || !defined(wantarray);
  42. return unless $old =~ /=/; # not a form
  43. map { s/\+/ /g; uri_unescape($_) }
  44. map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $old);
  45. }
  46. # Handle ...?dog+bones type of query
  47. sub query_keywords
  48. {
  49. my $self = shift;
  50. my $old = $self->query;
  51. if (@_) {
  52. # Try to set query string
  53. my @copy = @_;
  54. for (@copy) { s/([;\/?:@&=+,\$%])/$URI::Escape::escapes{$1}/g; }
  55. $self->query(join('+', @copy));
  56. }
  57. return if !defined($old) || !defined(wantarray);
  58. return if $old =~ /=/; # not keywords, but a form
  59. map { uri_unescape($_) } split(/\+/, $old, -1);
  60. }
  61. # Some URI::URL compatibility stuff
  62. *equery = \&query;
  63. 1;